Thanks Larry! That was the problem! I want to display the driving time inside an infoWindow
On Jun 9, 2:48 pm, "[email protected]" <[email protected]> wrote: > On Jun 9, 11:06 am, Seth <[email protected]> wrote: > > > > > > > So I am working with V3 and I'm trying to calculation the driving time > > between two points (latlng). I already have the distance and I can get > > the driving time using the following code: > > > function getDrivingTime(start, end) { > > var response; > > var request = { > > origin : start, > > destination : end, > > travelMode : google.maps.DirectionsTravelMode.DRIVING}; > > > directionsService.route(request, function(response, status) { > > if (status == google.maps.DirectionsStatus.OK) { > > alert(response.routes[0].legs[0].duration.text); > > > } > > }); > > } > > > BUT there's no way to actually return a value within the route method. > > You can't even assign values outside of it, so I have no way of > > returning that string that has the driving time inside of it... I'd > > like to do this: > > > function getDrivingTime(start, end) { > > ... > > if (status == google.maps.DirectionsStatus.OK) { > > return response.routes[0].legs[0].duration.text; > > ... > > > } > > > but it never returns a value. I'm so confused. How can I get the > > driving time or duration using the GoogleMaps api? > > You can't return a response from an asynchronous callback function. > But you can store the return value in a global variable or display it > in a <div> on your page. You need to do whatever you need to do with > it inside the callback function (where you have your alert). > > What do you want to do with the returned value? > > -- Larry -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
