I think it might have something to do with the loop, but how do i
solve that?

On Jun 10, 12:58 am, Seth <[email protected]> wrote:
> Okay, nevermind, it's still not working:
>
>         $.get(searchURL, function(data) {
>                 var markers = 
> data.documentElement.getElementsByTagName("marker");
>                 for (var i = 0; i < markers.length; i++) {
>                         var latlng = new
> google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(ma 
> rkers[i].getAttribute("lng")));
>                        directionsService.route(request, function(response,
> status) {
>                            if (status == google.maps.DirectionsStatus.OK) {
>                                 var content = '<div style="overflow:hidden; 
> width:350px;height:
> 100px;">'+
>                                 
> '<strong>'+markers[i].getAttribute("name")+'</strong>'+
>                                 '<hr />'+
>                                 
> '<p><strong>'+markers[i].getAttribute("name")+'</strong>, is
> <strong>'+markers[i].getAttribute("distance")+' miles</strong> from
> your current location.<hr />'+
>                                 'total distance: 
> <strong>'+markers[i].getAttribute("distance")+'
> mi</strong>&nbsp;&nbsp;|&nbsp;&nbsp;driving time:
> <strong>'+response.routes[0].legs[0].duration.text+'</strong>'+
>                                 '</p>'+
>                                 '</div>';
>
> addMarkerAndInfoWindow(latlng','mouseover',content,true);
>                         });
>              }
>
> ....
>
> i'm getting 'can't call method getAttribute on undefined' now. But
> markers is defined, and it works fine without this directions call.
>
> On Jun 9, 9:53 pm, Seth <[email protected]> wrote:
>
>
>
> > 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.

Reply via email to