Distance between CLLocationCoordinate2D values

by @ralfebert · published September 05, 2021

To compute the distance between two geographic coordinates / two CLLocationCoordinate2D values you can use an extension that uses MapKit:

import MapKit

extension CLLocationCoordinate2D {

    /// Returns the distance between two coordinates in meters.
    func distance(to: CLLocationCoordinate2D) -> CLLocationDistance {
        MKMapPoint(self).distance(to: MKMapPoint(to))
    }

}

↗ MapKit distance(to:)
↗ Finding distance between CLLocationCoordinate2D points
↗ distance(to:) in Euclid package (perfoming the computation manually)