使用 GPS 地图 如何计算两点之间的距离
可能的重复:
用于计算距离的 GPS 坐标(以度为单位)
我正在捕获字符串string 如何分隔字符串中的纬度和经度 <+37.33168900, -122.03073100> +/- 100.00m (速度 -1.00 mp / course -1.00) @ 2011-08-26 12:56:57 +0530
当我调用位置管理器时,这个方法被调用
// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manage didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog@("%@",newLocation) //<+37.33168900, -122.03073100> +/- 100.00m (speed -1.00 mp / course -1.00) @ 2011-08-26 12:56:57 +0530
NSLog@("%@",oldLocation) //null
}
我的问题是如何保存我的旧位置以及如何使用 newlocation 和 oldlocation 如何计算我搜索谷歌的距离,但我找不到请帮助我。我非常苦恼如何保存旧位置。
Possible Duplicate:
GPS coordinates in degrees to calculate distances
using GPS I am capure the string string how to separate latitude and longitude in string <+37.33168900, -122.03073100> +/- 100.00m (speed -1.00 mp / course -1.00) @ 2011-08-26 12:56:57 +0530
when i am calling location manager this is method is called
// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manage didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog@("%@",newLocation) //<+37.33168900, -122.03073100> +/- 100.00m (speed -1.00 mp / course -1.00) @ 2011-08-26 12:56:57 +0530
NSLog@("%@",oldLocation) //null
}
My problem is how to save my old location and how to using newlocation and oldlocation how to calculate the distance i searched for google but i can't find out please help me. i am very struggle for how to save oldLocation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
为了保存两个位置,您应该使用一个属性。
You can use
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
In order to save the two locations, you should use a property.
如果你想从字符串
<+37.33168900, -122.03073100> 获取纬度和经度+/- 100.00m (速度 -1.00 mp / course -1.00) @ 2011-08-26 12:56:57 +0530
你可以通过正则表达式找到第一个 < >并用逗号分隔。如果你想这样做,如何做到这一点是你的工作,但 SDK 为你提供了更方便的阅读 位置感知编程指南了解更多信息。If you want to get latitude and longitude from string
<+37.33168900, -122.03073100> +/- 100.00m (speed -1.00 mp / course -1.00) @ 2011-08-26 12:56:57 +0530
you could get it with regex by finding in first < > and separate by comma. How to do that is your work if you want to do it this way, but SDK provide you with more convenient read Location Awareness Programming Guide for more information.每当您开始监视您的位置时,第一次调用此方法可能会得到一个为 null 的 oldLocation。只是因为你的 iPhone 不知道它以前在哪里。
如果您在应用程序中多次开始和停止更新您的位置,并且您仍然想知道最后一个位置是什么,只需保存一个代表您的 oldLocation 的静态对象,并在收到委托调用后更新它。
Whenever you start watching your location, the first call of this method might have an oldLocation which is null. Just because your iPhone doesnt know where it was before.
if you start and stop updating your location several times in your app and you still want to know what the last location was just hold a static object which represents your oldLocation and update it after receiving the delegation call.