driving-distance

How do I get driving time from Google Maps API?

拥有回忆 提交于 2019-12-01 04:58:19
问题 I use the following function to estimate the time (in hours) to drive a certain distance, assuming an average speed of 65 km/h: distHoras <- function(origin, destination){ xml.url <- paste0('http://maps.googleapis.com/maps/api/distancematrix/xml?origins=', origin, '&destinations=', destination, '&mode=driving&sensor=false') xmlfile <- xmlParse(getURL(xml.url)) dist <- xmlValue(xmlChildren(xpathApply(xmlfile,"//distance")[[1]])$value) distance <- as.numeric(sub(" km", "", dist)) time <-

How to get total driving distance with Google Maps API V3?

社会主义新天地 提交于 2019-11-27 19:44:17
I used to be able to get it like this: directionsService.route(directionsRequest, function(directionsResult, directionsStatus) { var directionsRenderer = new google.maps.DirectionsRenderer({ directions: directionsResult, map: map }); $('#distance').text(directionsResult.trips[0].routes[0].distance.text) $('#duration').text(directionsResult.trips[0].routes[0].duration.text) }) But it looks like they changed their API on me! Looks like trips is no longer there, and routes only gives you a bunch of legs... do I really have to iterate over all the legs and sum up the distance now? As per Leniel's