Remaining distance and path on GMSPath from current Location

567 Views Asked by At

I am trying to update remaning distance and duration while traveling by using Google map API. I have a whole path, duration and distance but when he cover the distance, how can I get the the remaining distance and duration? I have tried GMSGeometryDistance but it's not giving me the correct distance. and I also don't want to call API again, but methods like 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

There are 0 best solutions below