I have this code:

    var directionsService = new google.maps.DirectionsService();

    var request = {
      origin : start,
            destination : end,
            travelMode : google.maps.DirectionsTravelMode.DRIVING

directionsService.route(request, function(response, status) {
    var coords;
    if (status == google.maps.DirectionsStatus.OK) {
        coords = google.maps.geometry.encoding.decodePath(response.routes[0].overview_polyline.points);

Yesterday the decodePath brought coordinates whose name of variables was Ya and Za, today became hb and ib. Why?


You shouldn't access the coordinates using the property names (i.e. 'Ya' and 'Za') instead use the .lat() and .lng() methods of the google.maps.LatLng object.

So I assume your callback function loops through the array of the coordinates (as variable 'coords'). The simple example below would loop through this array and print out each coordinate to the console in the fashion yy.yyyyy,-xx.xxxx

function callback(coords){
    var i;

This code assumes that the variable 'coords' is the overview_path property of the DirectionsRoute object (part of the DirectionsResult object.). This should be what you are getting by using the decodePath() function.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.