Created
October 14, 2011 21:00
-
-
Save ajokela/1288322 to your computer and use it in GitHub Desktop.
Longitude and Latitude - Distance between points
This file contains hidden or 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