从当前位置到GMSPath的剩余距离和路径

时间:2016-10-24 11:32:49

标签: ios swift google-maps google-api gmsplace

我正在尝试使用Google地图API更新旅行时的重复距离和持续时间。我有一个完整的路径,持续时间和距离但是当他覆盖距离时,我怎样才能获得剩余的距离和持续时间?我试过GMSGeometryDistance,但它没有给我正确的距离。而且我也不想再次调用API,而是像GMSGeometryDistance这样的方法。

    let to = CLLocationCoordinate2D(latitude: 24.948021, longitude: 67.091186)
    let from = CLLocationCoordinate2D(latitude: 24.891592, longitude: 67.084320)
    let camera = GMSCameraPosition.cameraWithTarget(to, zoom: 12)
    let mapView = GMSMapView.mapWithFrame(CGRectZero, camera:camera)

    GoogleMapsServices.drawPath(mapView, fromPoint:from, toPoint: to, completionHandler: {(json: JSON, path: GMSPath) -> () in

        if GMSGeometryIsLocationOnPathTolerance(to, path, true, 5) {
           print(GMSGeometryDistance(from, to))
        }
    })

    self.view = mapView

0 个答案:

没有答案