This question already has answers here:
Distance between two coordinates with CoreLocation
(4个答案)
6年前关闭。
我有特定地点的经度和纬度,我想计算距离,所以我怎么计算呢?
您还需要将
(4个答案)
6年前关闭。
我有特定地点的经度和纬度,我想计算距离,所以我怎么计算呢?
最佳答案
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
NSLog(@"Distance i meters: %f", [location1 distanceFromLocation:location2]);
[location1 release];
[location2 release];
您还需要将
CoreLocation.framework
添加到您的项目中,并添加import语句:#import <CoreLocation/CoreLocation.h>