可能的重复:
GPS 坐标(以度为单位)来计算距离 https://stackoverflow.com/questions/6994101/gps-coordinates-in-degrees-to-calculate-distances
如何在 iPhone 版 gmap 中使用经纬度计算两地之间的距离?
在 iPhone 版 gmap 中使用经纬度计算两个地点之间的距离
你必须使用核心定位框架。因此,不要忘记添加并导入核心位置框架。
Objective-C
#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];
Swift
import CoreLocation
let locA = CLLocation(latitude: lat1, longitude: long1)
let locB = CLLocation(latitude: lat2, longitude: long2)
let distance = locA.distance(from: locB)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)