我有两个MKCoordinateRegion
对象。基于这些对象的值,我在地图上制作了两个annotations
。 后来我计算这两个位置之间的距离:计算基于道路的两个位置之间的距离
CLLocationCoordinate2D pointACoordinate = [ann coordinate];
CLLocation *pointALocation = [[CLLocation alloc] initWithLatitude:pointACoordinate.latitude longitude:pointACoordinate.longitude];
CLLocationCoordinate2D pointBCoordinate = [ann2 coordinate];
CLLocation *pointBLocation = [[CLLocation alloc] initWithLatitude:pointBCoordinate.latitude longitude:pointBCoordinate.longitude];
float distanceMeters = [pointBLocation distanceFromLocation:pointALocation];
distanceMeters = distanceMeters/1000;
但我是个不知道,我值获得是正确的。
这些值是否是距离?
基于道路可以得到距离吗?
我需要用户必须通过汽车的距离。
但我已经在我的代码中使用CLLocation和distanceFromLocation:( – 1110
yup,你不会通过道路得到确切的距离,因为api会说“这种方法通过跟踪曲线之间的一条直线来测量两个位置之间的距离的地球“,你将不得不使用谷歌地图方向api。 –