Last active
September 26, 2019 02:59
-
-
Save jesty/7b2a8e31d56c13a6adff to your computer and use it in GitHub Desktop.
Compute heading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* A heading is defined in degrees from true north, where headings are measured clockwise from true north (0 degrees). | |
* The parameter for this function are two array that identifies a geo point with latitude at position 0 and longitude | |
* at position 1. | |
* This function is similar to https://developers.google.com/maps/documentation/javascript/geometry. I developed because | |
* I need it on Meteor server side. | |
* The result is a value between -180 and 180. | |
*/ | |
var computeHeading = function (start, end){ | |
var lat1 = start[0]*Math.PI/180; | |
var lat2 = end[0]*Math.PI/180; | |
var lng1 = start[1]*Math.PI/180; | |
var lng2 = end[1]*Math.PI/180; | |
return Math.atan2( Math.sin(lng2-lng1) * Math.cos(lat2), Math.cos(lat1)*Math.sin(lat2)-Math.sin(lat1)*Math.cos(lat2)*Math.cos(lng2-lng1))*180/Math.PI; | |
} |
Hi!
Please can you declare more cause teh code is not working when i run my program :)
thnx for helping:)
i think i fix my error :)
thnx:)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
holly crap I love you!!!