Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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