当我的取放位置相同时,如何计算出租车所覆盖的点之间的总距离?

时间:2019-06-24 06:03:54

标签: ios gps mapkit distance cllocationmanager

我正在开发一些与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)
}

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

1 个答案:

答案 0 :(得分:0)

为此,您需要处理特定事件。当出租车到达接机地点并开始行驶时,您需要从出租车应用程序中开始捕获位置。您必须有ArrivedOnPickupRideStartedOnWayCompleted之类的事件。

就像@Lu_一样,建议开始捕获数组中的坐标,直到行驶结束。在骑行完成时,您可以通过实现 http://findnerd.com/list/view/How-to-calculate-distance-from-array-of-coordinates-in-iOS/17529/

  

注意:您还可以使用Google Direction api来绘制路径并获取距离,但这不能确保驾驶员选择的路线与Google提供的路线相同