找出矩形中的长/纬度

Ric*_*end 3 c# maps geospatial coordinates

给定一个左上角的长/纬度和一个右下角的长/纬度,如何确定给定的长/纬度是否落在矩形内?

理想情况下,我会看到类似的东西

bool IsWithinArea(float topLeftLat,float topLeftLong,
   float bottomRightLat,float bottomRightLong,float testLat,float testLong)
Run Code Online (Sandbox Code Playgroud)

更新

一个问题是从long/lat创建的矩形可能来自旋转的地图,因此右下角并不总是大于左上角...

Sno*_*ear 5

我们可以比琐碎的检查更有趣:

return new Rect(topLeftLat, topLeftLong, bottomRightLat - topLeftLat, bottomRightLong - topLeftLong)
      .Contains(testLat, testLong);
Run Code Online (Sandbox Code Playgroud)

PS:Rect.Contains(...)方法