为什么 iOS CLLocation 显示不正确的值?

Why iOS CLLocation shows incorrect values?

我正在尝试计算 2 个坐标之间的距离。为此,我这样做:

func setupLocationManager() {
    if CLLocationManager.authorizationStatus() == .NotDetermined {
        locationManager.requestWhenInUseAuthorization()
    }

    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.startUpdatingLocation()
}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let latitude = locations.last?.coordinate.latitude
    let longitude = locations.last?.coordinate.longitude

    let myLocation = CLLocation(latitude: latitude!, longitude: longitude!)
    let targetLocation = CLLocation(latitude: 41.4381022, longitude: 46.604910)

    let distance = myLocation.distanceFromLocation(targetLocation)
    print(distance)
}

我正在打卡Google地图上有13公里的距离!但是我的应用程序显示了 2-3 公里!

我该如何改进?

Google 地图为您提供两个位置之间的路线距离,CLLocation 为您提供两个位置之间的鸟瞰距离。

来自documentation

This method measures the distance between the two locations by tracing a line between them that follows the curvature of the Earth. The resulting arc is a smooth curve and does not take into account specific altitude changes between the two locations.

这是一个基于 working GPS app.

的示例
import CoreLocation

public class SwiftLocation: NSObject, CLLocationManagerDelegate {

    private let locationManager = CLLocationManager()
    private var latestCoord: CLLocationCoordinate2D

    init(ignore:String) {

        locationManager.requestAlwaysAuthorization()
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.distanceFilter = kCLDistanceFilterNone
        locationManager.startUpdatingLocation()
        latestCoord = locationManager.location!.coordinate

        super.init()

        locationManager.delegate = self
    }

    private func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {

        latestCoord = manager.location!.coordinate

    }

    public func getLatest() -> CLLocationCoordinate2D {
        return latestCoord
    }
}