判断长/纬度是否在矩形内
给定左上角的长/纬度和右下角的长/纬度,我如何找出给定的长/纬度是否落在矩形内?
理想情况下,我会查看类似
bool IsWithinArea(float topLeftLat,float topLeftLong,
float bottomRightLat,float bottomRightLong,float testLat,float testLong)
Update 的
内容。一个问题是,从长/纬度创建的矩形可能来自旋转的地图,因此右下角并不总是大于左上角......
Given a top-left long/lat and a bottom-right long/lat how can i find out if a given long/lat falls within the rectangle ?
Ideally i would be looking at something like
bool IsWithinArea(float topLeftLat,float topLeftLong,
float bottomRightLat,float bottomRightLong,float testLat,float testLong)
Update
The one problem is that the rectangle created from the long/lat may be from a rotated map, so bottom right will not always be greater than top left...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我们可以让它比琐碎的检查更有趣:
PS: Rect.Contains(... )方法
We can make it more interesting than trivial checks:
P.S.: Rect.Contains(...) method
不确定我是否想简单
Not sure if I'm thinking to simple
假设 Lat 是 x 坐标,Long 是 y 坐标,并且还假设坐标系的原点位于左上角:
Assuming that Lat is the x coordinate und Long is the y coordinate and also assuming that the coordinate systems has its origin at the left top:
一种方法是将长/纬度对标准化为简单的 x/y 坐标。那么它应该是一个简单的练习来确定一个点是否落在矩形内。
长/纬度到 x/y 的转换可以在这里找到:将纬度/经度转换为X/Y 坐标
One approach would be to normalize your long/lat pairs to simple x/y coordinates. Then it should be a simple excersize to determine if a point falls within the rectangle.
long/lat to x/y conversion can be found here: Convert Lat/Longs to X/Y Co-ordinates