Last active
September 12, 2016 05:24
-
-
Save ronsuez/6eca2f68eb8bde4b4bdf17f8017ea4a7 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
//put here | |
var getDistance = function(p1, p2) { | |
var R = 6378137; // Earth’s mean radius in meter | |
var dLat = rad(p2.lat() - p1.lat()); | |
var dLong = rad(p2.lng() - p1.lng()); | |
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + | |
Math.cos(rad(p1.lat())) Math.cos(rad(p2.lat())) | |
Math.sin(dLong / 2) * Math.sin(dLong / 2); | |
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); | |
var d = R * c; | |
return d/1000; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment