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

1 Answer 1

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.

6
  • Thanks for your answer.But it is not what Im looking for. The question below is extractly what I want. stackoverflow.com/questions/11661965/… Can you help me in this situation.
    – Thanh Le
    Commented Mar 4, 2013 at 7:39
  • I am not sure I am understanding what you want. You want the images? Use a sprite.
    – Rafe
    Commented Mar 4, 2013 at 8: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
    Commented Mar 4, 2013 at 8: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
    Commented Mar 4, 2013 at 9: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
    Commented Mar 4, 2013 at 9:39

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