如何使用gmap for iPhone中的纬度 - 经度计算两个地方之间的距离? 使用gmap for iPhone中的纬度 - 经度计算两个地方之间的距离
答案 0 :(得分:260)
您必须使用核心位置框架。所以不要忘记添加&导入核心位置框架。
#import <CoreLocation/CoreLocation.h>
CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
CLLocationDistance distance = [locA distanceFromLocation:locB];
//distance in Meters
//1 meter == 100 centimeter
//1 meter == 3.280 feet
//1 square meter == 10.76 square feet
[locA release];
[locB release];
import CoreLocation
let locA = CLLocation(latitude: lat1, longitude: long1)
let locB = CLLocation(latitude: lat2, longitude: long2)
let distance = locA.distance(from: locB)
答案 1 :(得分:11)
如果您有location参数,请创建2个CLLocations并使用[location1 distanceFromLocation:location2]
方法。