3

我正在尝试使用 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
4

0 回答 0