如何测量两个CLLocations之间的距离(米)?

Ily*_*pan 18 cocoa-touch objective-c core-location cllocation

我怎样才能得到两米之间的距离CLLocationCLLocation它没有提供任何方法来实现它.

Jon*_*lli 61

CLLocationDistance distance = [aCLLocationA distanceFromLocation:aCLLocationB];
// distance is a double representing the distance in meters
Run Code Online (Sandbox Code Playgroud)

  • http://developer.apple.com/library/ios/DOCUMENTATION/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html#//apple_ref/doc/uid/TP40007126-CH3-SW18 (2认同)

Nit*_*Nit 5

CLLocationDistance distance = [secondLocation distanceFromLocation:firstLocation];  //      distance is expressed in meters

CLLocationDistance kilometers = distance / 1000.0;
// or you can also use this..
CLLocationDistance meters = distance;

NSString *distanceString = [[NSString alloc] initWithFormat: @"%f", kilometers];

flot totaldistancecovered = [distanceString floatValue];

//Now,you can use this float value for addition...
// distanceMoved  should be float type variable which is declare in .h file...

 distanceMoved = distanceMoved + totaldistancecovered ;
 theLabel.text = [NSString stringWithFormat: @"%f meters", distanceMoved];
Run Code Online (Sandbox Code Playgroud)

希望对你有帮助...