2011-08-26 37 views
0
之间的距离

可能重复:
GPS coordinates in degrees to calculate distances使用GPS地图如何计算两点

使用GPS我capure的串串如何在字符串<分开纬度和经度+37.33168900,-122.03073100> +/- 100.00m(速度-1.00 mp/course -1.00)@ 2011-08-26 12:56:57 +0530

当我打电话给位置管理员R这是方法被称为

// Delegate method from the CLLocationManagerDelegate protocol. 
- (void)locationManager:(CLLocationManager *)manage didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    [email protected]("%@",newLocation) //<+37.33168900, -122.03073100> +/- 100.00m (speed -1.00 mp/course -1.00) @ 2011-08-26 12:56:57 +0530 

    [email protected]("%@",oldLocation) //null 
} 

我的问题是如何将我的老位置,以及如何保存到使用newlocation和oldlocation如何计算我搜索谷歌的距离,但我不能找到,请帮助我。我很难为如何保存oldLocation。

+1

-1你可以更具体一点吗? – JohnJohnGa

回答

1

您可以使用- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location

为了挽救这两个位置,你应该使用属性。

0

如果你想从字符串<+37.33168900, -122.03073100> +/- 100.00m (speed -1.00 mp/course -1.00) @ 2011-08-26 12:56:57 +0530得到纬度和经度,你可以通过在第一个<>中找到并用逗号分隔。如何做到这一点是你的工作,如果你想要做这种方式,但SDK为您提供更方便更多信息,请阅读Location Awareness Programming Guide

0

每当你开始看你的位置,这种方法的第一次调用可能有一个oldLocation是零。仅仅因为你的iPhone不知道它以前在哪里。

,如果你开始和停止更新自己的位置多次在您的应用程序,你还是想知道最后的位置被牵住它代表你的oldLocation静态对象和接受委托电话后更新。

static CLLocation * myLastLocation; 

- (void)locationManager:(CLLocationManager *)manage didUpdateToLocation:(CLLocation*) newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    [email protected]("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! 
}