Ho to get Heading Direction from from 2 lat,long points

3,560 views
Skip to first unread message

abhishek

unread,
Apr 18, 2011, 10:51:52 PM4/18/11
to google-earth-...@googlegroups.com
i am doing a live 3d map based on live gps points from a moving car.
how to get  heading direction (x degrees from north) so that i can set the lookAt point towards correct heading direction.
 
Can i get heading direction from 2 gps points (lat,long) -> (lat,long)
 
i also wants to move nicely on the road and i am using (speed_teleport) as setflytospeed option. Any way to set the speed of this teleport?
i dont want to pan with zooming in and out, i just want to move my car on streets looking from back at 45 degrees.
 

StarTraX

unread,
Apr 18, 2011, 11:29:33 PM4/18/11
to KML Developer Support - Google Earth Plug-in
You have to use trigonometry.
Working in radians, not degrees, and assuming the two points are
fairly close: metres not 100's of kilometres (to ensure cos(lat1) is
much the same as cos(lat2)) then:
tan(heading angle) = (lon2 - lon1)*cos(lat1)/(lat2 - lat1)
You'll have to use the math.atan2 function to get the correct sign on
the result.

abhishek

unread,
Apr 19, 2011, 12:28:35 AM4/19/11
to google-earth-...@googlegroups.com
Hi thanks star thanks,
 i think i worked it out..
from the trignometry of course .. luckly javascript Math object gives all the functions we need to do it...
 

 

 

 

Stanislav Chachkov

unread,
Apr 19, 2011, 5:49:05 PM4/19/11
to KML Developer Support - Google Earth Plug-in
You can use createVantageView from gex http://code.google.com/p/earth-api-utility-library/

abhishek

unread,
Apr 19, 2011, 8:05:41 PM4/19/11
to google-earth-...@googlegroups.com
thanks for that
i also found one link - very helpful
 
though i am sticking to my java code for now as its working fine :

function GetDirection(lat1, lon1, lat2, lon2) {

var br = 0;

br = Math.atan2(Math.sin(lon2 - lon1) * Math.cos(lat2), Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1)) % (2 * Math.PI);

br = (br * 180) / Math.PI;return br;

}

gautam yadav

unread,
Sep 15, 2012, 7:13:46 AM9/15/12
to google-earth-...@googlegroups.com
thanks abhisek
it's working fine

gautam yadav

unread,
Sep 15, 2012, 7:15:30 AM9/15/12
to google-earth-...@googlegroups.com

Since atan2 returns values in the range -π ... +π (that is, -180° ... +180°), to normalise the result to a compass bearing (in the range 0° ... 360°, with -ve values transformed into the range 180° ... 360°), convert to degrees and then use (θ+360) % 360, where % is modulo.

For final bearing, simply take the initial bearing from the end point to the start point and reverse it (using θ = (θ+180) % 360).

bimat

unread,
Sep 17, 2012, 5:50:58 AM9/17/12
to google-earth-...@googlegroups.com
Hi thanks,


Vào 18:13:46 UTC+7 Thứ bảy, ngày 15 tháng chín năm 2012, gautam yadav đã viết:
Reply all
Reply to author
Forward
0 new messages