Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Can I calculate distanse between two lngltd points on car with routes? #52

Closed
blaxi opened this issue Jun 19, 2012 · 3 comments
Closed

Comments

@blaxi
Copy link

blaxi commented Jun 19, 2012

With GMapsAPI i can do this with that way:
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
var legs = response.routes[0].legs;
var totalDistance = legs[0].distance.value;
var METERS_TO_MILES = 0.000621371192;
alert((Math.round( totalDistance * METERS_TO_MILES * 10 ) / 10)+' miles');
}
});

@hpneo
Copy link
Owner

hpneo commented Jun 19, 2012

Hi, you can use getRoutes method this way:

map.getRoutes({
  origin: [origin.lat(), origin.lng()],
  destination: [destination.lat(), destination.lng()],
  travelMode: 'driving',
  callback: function(e){
    routes = e;
    alert(routes[0].legs[0].distance.value);
  }
});

@thomasjoyce
Copy link

how do you get the google map traffic time?
"In current traffic: 37 mins" included with the distance?

Thanks for your help :- )

@thomasjoyce
Copy link

Never mind, i found it. Added it here for others to see, if needed. :- )

alert(routes[0].legs[0].duration.value

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants