views:

169

answers:

2

I'm developing an application in which I need to display a message showing where to turn after user clicks a position on route highlighted with the help of directions on Google map.

There's this Groute class which provides much of the information like distance, duration between two places, but it doesn't give information about direction.

Can anybody please help? It's urgent.

+1  A: 

From the GRoute you can use .getStep(i) to obtain the GStep object for each step in the GRoute. .getNumSteps() tells you how many GSteps are in a GRoute.

For each GStep you can call .getDescriptionHtml() which will return the formatted description for that individual step. Like "Take the 1st right onto A5099/Coronation St" or "At the roundabout, take the 3rd exit onto A6/Garstang Rd heading to Preston".

To relate the GStep to a specific vertex of the polyline, scan through all the GSteps looking for the last one with a getPolylineIndex() that's less than or equal to the specified vertex. Like this:

      var v = 66; // The vertex you are looking for

      var targetStep = route.getStep(0);
      for (var j=0; j<route.getNumSteps(); j++) {
        var step = route.getStep(j);
        if (step.getPolylineIndex() < v) targetStep = step;
      }
      GLog.writeHtml(targetStep.getDescriptionHtml());

Don't attempt to parse the .getDescriptionHtml() because the details of the structure change from time to time and vary depending on the country of the route and the host language or locale.

Mike Williams
Thanx Mike Williams.. Exactly what I was looking for!
neha
Mike Williams, I tried implementing all the steps you pointed out. But I'm stuck at the step of relating GStep to a specific vertex of the polyline. I'm not getting the meaning of "scan through all the GSteps looking for the last one with a getPolylineIndex() that's less than or equal to the specified vertex". Can you please help me?
neha
I've edited a code sample into the Answer because I don't know if it's possible to do formatted text inside a Comment.
Mike Williams
A: 

I need exactky the opposite. Is it possible to retrieve only the streets names?

Fabio