使用 GPS 地图 如何计算两点之间的距离

发布于 2024-12-02 01:12:26 字数 869 浏览 1 评论 0原文

可能的重复:
用于计算距离的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沉鱼一梦 2024-12-09 01:12:26

您可以使用 - (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.

笨笨の傻瓜 2024-12-09 01:12:26

如果你想从字符串 <+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.

故人爱我别走 2024-12-09 01:12:26

每当您开始监视您的位置时,第一次调用此方法可能会得到一个为 null 的 oldLocation。只是因为你的 iPhone 不知道它以前在哪里。

如果您在应用程序中多次开始和停止更新您的位置,并且您仍然想知道最后一个位置是什么,只需保存一个代表您的 oldLocation 的静态对象,并在收到委托调用后更新它。

static CLLocation * myLastLocation;

- (void)locationManager:(CLLocationManager *)manage didUpdateToLocation:(CLLocation*) newLocation fromLocation:(CLLocation *)oldLocation
{
     NSLog@("Working with the new location: %@",newLocation); 

     // Save it as the old location
     myLastLocation = newLocation;

     // Your problem still exists that the first call will have myLastLocation == nil!
}

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.

static CLLocation * myLastLocation;

- (void)locationManager:(CLLocationManager *)manage didUpdateToLocation:(CLLocation*) newLocation fromLocation:(CLLocation *)oldLocation
{
     NSLog@("Working with the new location: %@",newLocation); 

     // Save it as the old location
     myLastLocation = newLocation;

     // Your problem still exists that the first call will have myLastLocation == nil!
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文