There can be multiple legs within a single directions route. It looks like you're only retrieving distance for the first one, e.g. legs[0].
Did you try looping through the entire legs Array to sum up the distance for each? Thanks, Dann On Tue, Apr 13, 2010 at 11:06 AM, xinder <[email protected]> wrote: > Hi everybody! I need to know the distance between two points. I have > the LatLng object which their information. I have used the > DirectionsService class and route method and I have something like > this: > > var request = { > origin:myLatLng1, > destination:myLatLng2, > travelMode: google.maps.DirectionsTravelMode.DRIVING > }; > directionsService.route(request, function(result, status) { > if (status == google.maps.DirectionsStatus.OK) { > myArray[i] = result.routes[0].legs[0].distance.value // var i > is not important in this context > } > }); > > So, when I show myArray[i] the distance is incorrect. Anybody knows > where is the problem? > Thanks a lot. > > -- > 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]<google-maps-js-api-v3%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-maps-js-api-v3?hl=en. > > -- Daniels Lee Developer Programs Engineer Google, Inc. 345 Spear Street San Francisco, CA 94105 650 253 0967 -- 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.
