Finding distance between CLLocationCoordinate2D points

前端 未结 7 1030
醉梦人生
醉梦人生 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:11

        let point1 = MKMapPointForCoordinate(myLocation)
        let point2 = MKMapPointForCoordinate(friendLocation)
        let distance = MKMetersBetweenMapPoints(point1, point2)/1000
        let distanceStr = NSString(format: "%.3f", distance)
    

    Simple version of Valleri's answer. Divide by 1000 to get KM followed by conversion to string.

提交回复
热议问题