如何计算两地之间的距离? iPhone 版 Google 地图有可用的服务吗?
我想放置设施来显示用户选择的两个地点之间的距离。
是否有任何示例源代码/服务可用于执行此操作?
提前致谢。
I want to put facility to display distance between two places selected by user.
Is there any sample source code / service available to do so?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
CoreLocation Framework 提供了以下功能计算出两点之间的距离(以米为单位):
您可以使用纬度和经度初始化
CLLocation
对象:The CoreLocation Framework provides the capability to work out the distance, in meters, between two points:
You can initialize a
CLLocation
object with latitude and longitude:如果您有两个 CLLocation 对象,您可以这样做:
但是,这只是点对点。如果你想要特定路线上的距离,那就完全是另一回事了。
If you have two CLLocation objects, you can just do:
However, that's just point-to-point. If you want the distance over a specific route, well, that's a whole other kettle of fish.
这是 CLLocation 框架的任务。使用已知的 2 个点坐标,您可以创建(如果还没有)2 个 CLLocation 对象,并使用
方法查找它们之间的距离。
This is a task for CLLocation framework. With known coordinates of 2 points you can create (if you don't have them already) 2 CLLocation objects and find a distance between them using
method.
我不熟悉 iPhone 开发,但这里是使用半正弦公式计算两点之间距离的 C# 代码:
MeasurementUnit 定义为:
I am not familiar with iPhone development, but here is the C# code for computing the distance between two points using the Haversine formula:
The MeasurementUnit is defined as:
这取决于您希望这两点之间有什么样的差异。在地图上我认为你不想要空中距离。然后你应该检查 http://iosboilerplate.com/
如果你仍然想使用空中距离,请使用核心位置。
It depends on which kind of difference you wanna have between both points. On the map I think you dont wanna the air distance. Then you should check http://iosboilerplate.com/
If you still wanna use the air distance, use Core Location.
返回从接收器位置到指定位置的距离(以米为单位)。 (在 iOS 3.2 中已弃用。使用
距离位置:
Returns the distance (in meters) from the receiver’s location to the specified location. (Deprecated in iOS 3.2. Use
the distanceFromLocation: