Created
August 5, 2016 15:32
-
-
Save fsschmitt/72defbbce66db86d4424db0e96b5e735 to your computer and use it in GitHub Desktop.
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 distance = function(lat1, lon1, lat2, lon2){ | |
var R = 6371e3; // metres | |
var φ1 = lat1 * Math.PI / 180; | |
var φ2 = lat2 * Math.PI / 180; | |
var Δφ = (lat2-lat1)* Math.PI / 180; | |
var Δλ = (lon2-lon1)* Math.PI / 180; | |
var a = Math.sin(Δφ/2) * Math.sin(Δφ/2) + | |
Math.cos(φ1) * Math.cos(φ2) * | |
Math.sin(Δλ/2) * Math.sin(Δλ/2); | |
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); | |
//distance in meters | |
var d = R * c; | |
return d; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment