Created
October 8, 2013 05:50
-
-
Save jinahadam/6880085 to your computer and use it in GitHub Desktop.
Distance betweeen two gps points
Haversine a = sin²(Δφ/2) + cos(φ1).cos(φ2).sin²(Δλ/2)
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
var R = 6371; // km | |
var dLat = (lat2-lat1).toRad(); | |
var dLon = (lon2-lon1).toRad(); | |
var lat1 = lat1.toRad(); | |
var lat2 = lat2.toRad(); | |
var a = Math.sin(dLat/2) * Math.sin(dLat/2) + | |
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2); | |
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); | |
var d = R * c; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment