是否有用于测地线纬度/经度坐标计算的库或框架?
我正在制作一个核心位置驱动的应用程序,我必须计算给定纬度/经度对的许多内容,例如:
到另一个纬度/经度坐标的距离
- < p>向 y 方向行进距离 x 时的目标纬度/经度坐标
有可以使用的开源工具吗?
I'm making a core-location driven app where I must calculate lots of things for a given latitude/longitude pair, such as:
Distance to another lat/long coordinate
The target lat/long coordinate when traveling a distance x into direction y
Is there something open sourced which can be used?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于您使用的是 CoreLocation,因此可以使用 CoreLocation 的 distanceFromLocation 正如 @progrmr 指出的。
另一方面,由于您指定了开源,而这不是开源的,您可以查看 GeographicLib按照@MikeT 建议的实现。
(我最初的答案,建议使用半正矢公式,是有缺陷的。正如@MikeT指出的,半正矢公式仅对球体有效。并且地球不是一个完美的球体。)
原始的,有缺陷的答案:
听起来像你想要半正矢公式。维基百科页面半正弦公式解释了它是什么(在底部的“外部链接”下)< /a> 包含许多实现的链接。我没有检查过,但我必须想象其中至少有一些是开源项目。Since you are using CoreLocation, you can use CoreLocation's distanceFromLocation as @progrmr points out.
On the other hand, since you specified open source, and that ain't open sourced, you can look at GeographicLib implementations as suggested by @MikeT.
(My original answer, suggesting the Haversine formula, was flawed. As @MikeT points out, the Haversine formula is only valid for spheres. And the Earth is not a perfect sphere.)
Original, flawed answer:
It sounds like you want the Haversine formula.The Wikipedia page for the Haversine formula explains what it is and (at the bottom, under "External links") contains links to many implementations. I haven't checked, but I have to imagine that at least some of them are open source projects.github 上有一些 C 函数可以从坐标出发对,或给定起点和航向的目的地坐标。 可以使用 CLLocation 实现的坐标之间的距离。
这些基于余弦球面定律并源自此处的算法和此处。
There are some C functions on github that does heading from a coordinate pair, or destination coordinates given start and heading. Distance between coordinates you can do with CLLocation.
These are based on the Spherical Law of Cosines and derived from the algorithms here and here.
GeographicLib 已用多种编程语言实现,包括 Java.该库计算旋转椭球体(或椭球体)上测地线的长度和相关数学属性。计算误差一般在微米范围内。
要查找两个坐标之间的距离:
然后获取
g.s12
作为两点之间的距离。问题中的第二个示例是使用
Direct
方法找到给定距离和方向的位置。GeographicLib has been implemented in several programming languages, including Java. The library calculates lengths and related mathematical properties of geodesics on ellipsoids of revolution (or spheroid). The calculation errors are generally in the range of micrometers.
To find the distance between two coordinates:
then get
g.s12
for the distance between the two points.The second example in the question, to project a location given distance and direction, is found using the
Direct
methods.