我有两个MapKit注释,显示纬度和经度。
有没有办法让我通过现有的Objective-C iOS API函数来计算两者之间的距离?
答案 0 :(得分:17)
MapKit framework包含许多功能,您会发现CLLocationDistance MKMetersBetweenMapPoints(MKMapPoint a, MKMapPoint b);
返回地图中两点之间的距离(以米为单位)。也许你可以用它来解决你的问题。
首先创建两个对应点,并获取距离:
MKMapPoint p1 = MKMapPointForCoordinate(coord1);
MKMapPoint p2 = MKMapPointForCoordinate(coord2);
CLLocationDistance dist = MKMetersBetweenMapPoints(p1, p2);
答案 1 :(得分:3)
您需要的是半胱氨酸公式:http://www.movable-type.co.uk/scripts/latlong.html
来自:http://en.wikipedia.org/wiki/Haversine_formula
您可以在此处找到Objective-C实施:http://www.jaimerios.com/?p=39
答案 2 :(得分:3)
CLLocation
distanceFromLocation
完成这项工作。
它给出了两个CLLocation
之间以米为单位的大圆距离。
我只是尝试并测试了它。
答案 3 :(得分:0)