我有两个 MapKit 注释,显示纬度和经度。
我有什么办法,通过现有的Objective-C iOS API函数来计算两者之间的距离吗?
最佳答案
MapKit framework包含许多函数,您会发现 CLLocationDistance MKMetersBetweenMapPoints(MKMapPoint a, MKMapPoint b);
返回 map 中两点之间的距离(以米为单位)。也许你可以用它来解决你的问题。
首先创建两个对应点,然后获取距离:
MKMapPoint p1 = MKMapPointForCoordinate(coord1);
MKMapPoint p2 = MKMapPointForCoordinate(coord2);
CLLocationDistance dist = MKMetersBetweenMapPoints(p1, p2);
关于objective-c - 将纬度和经度转换为米或公里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6803696/