0

Im using google direction service to get direction between two points in the map. I have successed with this problem. My prolem now is how to detect the direction image in direction image. I see a varius number of instruction like turn right, slight right, turns right. So I can handover all situations may be appear.

So my question is how to detect the directive images(or arrow images) like the image below. enter image description here

Thanh Le
  • 1,370
  • 2
  • 19
  • 30

1 Answers1

2
function toRad(value) { "use strict"; return value * (Math.PI / 180); }

function bearing(lat1, lon1, lat2, lon2) {
    "use strict";
    var dLon, x, y;
    lat1 = toRad(lat1);
    lat2 = toRad(lat2);
    dLon = toRad(lon2 - lon1);
    y = Math.sin(dLon) * Math.cos(lat2);
    x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
    return toBrng(Math.atan2(y, x));
}

Those two functions, when used by throwing two sets of long,lats at them will give you the bearing.

Just work out the bearing you are headed to from the bearing you are at and that will tell you the direction.

Rafe
  • 793
  • 6
  • 15
  • Thanks for your answer.But it is not what Im looking for. The question below is extractly what I want. http://stackoverflow.com/questions/11661965/google-maps-navigation-symbols Can you help me in this situation. – Thanh Le Mar 04 '13 at 07:39
  • I am not sure I am understanding what you want. You want the images? Use a sprite. – Rafe Mar 04 '13 at 08:33
  • I dont want the images. I want to detect the image with the instruction. Your function is not cover all situation in the instruction. Thanks for your support. – Thanh Le Mar 04 '13 at 08:50
  • Let me see if I am understanding you correctly. You want to work out from the instructions in the directionresult, what the exact http img source is for a corresponding image? – Rafe Mar 04 '13 at 09:21
  • Sorry for my english if I made you misunderstand. Let me explain: In the result in google direction api, we have a html_instruction tag. This tag contains the direction instruction. I have detect the direction image (for example: turn left image, u-turn image, roundabout image,...). I am very appriated for your help. – Thanh Le Mar 04 '13 at 09:39
  • I think the question is, "What are all possible values for the `maneuver` elements in a Directions API response?" – Kevin Krumwiede Sep 11 '14 at 22:29