Finding distance between CLLocationCoordinate2D points

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

    Swift 5:

    extension CLLocation {
        
        /// Get distance between two points
        ///
        /// - Parameters:
        ///   - from: first point
        ///   - to: second point
        /// - Returns: the distance in meters
        class func distance(from: CLLocationCoordinate2D, to: CLLocationCoordinate2D) -> CLLocationDistance {
            let from = CLLocation(latitude: from.latitude, longitude: from.longitude)
            let to = CLLocation(latitude: to.latitude, longitude: to.longitude)
            return from.distance(from: to)
        }
    }
    
    0 讨论(0)
提交回复
热议问题