当我的接送地点相同时,如何计算出租车覆盖的点之间的总距离?

How to calculate total distance between points covered by a Cab when my pickup and drop location are same?

我正在开发一些与 Cab 相关的应用程序。但是我有一个问题,如果我的上车地点和下车地点相同,那么我如何计算当时出租车行驶的距离。

目前我正在使用下面提到的代码计算从一个坐标到另一个坐标的距离。

func calculateDistance(pickLat: String, pickLong: String, dropLat: String, dropLong: String) {
    let coordinate0 = CLLocation(latitude: Double(pickLat)!, longitude: Double(pickLong)!)
    let coordinate1 = CLLocation(latitude: Double(dropLat)!, longitude: Double(dropLong)!)

    let distanceInMeters = coordinate0.distance(from: coordinate1) // result is in meters
    print(distanceInMeters)
}

这是我正在做的正常过程。请帮帮我。

为此,您需要处理特定事件。当出租车到达接载点并开始乘车时,您需要开始从您的出租车应用程序捕获位置。你必须有像 ArrivedOnPickup , RideStarted,OnWay, Completed.

这样的事件

就像@Lu_建议开始捕捉数组中的坐标,直到骑行完成。骑行完成后,您可以通过实施获得距离 http://findnerd.com/list/view/How-to-calculate-distance-from-array-of-coordinates-in-iOS/17529/

Note: You can also use Google Direction api to draw path and get the distance but this will not ensure that you route taken by the driver and route provided by the google will be same