Finding distance between CLLocationCoordinate2D points

前端 未结 7 1121
醉梦人生
醉梦人生 2020-12-10 00:13

I know from documentation we can find distance between two CLLocation points using the function, distanceFromLocation:. But my problem is I dont ha

7条回答
  •  清歌不尽
    2020-12-10 01:07

    If it is ok for you to get distance in meters between points, then

    CLLocationCoordinate2D coordinate1 = 
    CLLocationCoordinate2D coordinate2 = 
    …
    MKMapPoint point1 = MKMapPointForCoordinate(coordinate1);
    MKMapPoint point2 = MKMapPointForCoordinate(coordinate2);
    CLLocationDistance distance = MKMetersBetweenMapPoints(point1, point2);
    

    will return the distance between two points. No needs to create CLLocation by given CLLocationCoordinate2D. This defines are available since iOS 4.0

提交回复
热议问题