查找给定位置(纬度、经度)是否在两个坐标的 BoundingBox 内(route-me)
我正在使用 Route-Me 项目开发 iPhone 应用程序。 我正在使用一种名为“latitudeLongitudeBoundingBoxForScreen”的方法,它返回一组两个坐标。以屏幕的纬度/经度定义东北角和西南角。这似乎工作正常。
我的问题是如何确定给定点(纬度/经度)是否在这两个坐标(东北、西南)的边界内?
预先非常感谢您的帮助。
I am working on an iPhone app using the Route-Me project.
I am using a method called 'latitudeLongitudeBoundingBoxForScreen' which returns a set of two cooördinates. Defining the Northeast and Southwest corners in lat/lon of your screen. This seems to work fine.
My question is how can I determine whether a given point (lat/lon) is within the boundaries of these two coordinates (northeast,southwest)?
Thank you very much in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于多边形中的一般点,点包含测试似乎可以假设一个简单的等矩形投影(x = lon,y = lat)。
由于您知道东北角和西南角,因此可以计算西北角和东南角。另外,请记住,您的边界多边形(盒子)必须遵循缠绕约定(您不能在点包含测试中抛出点)。
如果边界框越过 180 lon 线,这将会中断。简单的解决方法是,如果穿过 180 经线的框将负经度添加 360。这不是一个有效的导航点,但它使数学有效。
这在两极周围也不起作用。
For general point in a polygon, the Point Inclusion Test seems to work assuming a trivial Equirectanglular projection (x = lon, y = lat).
Since you know the north-east and south-west, you can compute the north-west and south-east corners. Also, keep in mind that your bounding polygon (box) must following a winding convention (you just can't throw points at the Point Inclusion Test).
This will break if the bounding box goes across the 180 lon line. The simple fix is if the box that crosses 180 lon line is to add 360 to the negative longitude. This isn't a valid navigation point but it makes the math work.
This also will not work around the poles.
我知道已经过去很长时间了,但也许有人仍然感兴趣。
I know that a long time has passedby, but maybe someone still interested.