Created
November 2, 2011 09:11
-
-
Save slaypni/1333234 to your computer and use it in GitHub Desktop.
calculate Hubeny's distance from Geolocation
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
// http://yamadarake.web.fc2.com/trdi/2009/report000001.html | |
function calcHubenyDistance(lat1, lon1, lat2, lon2){ | |
var a = 6378137.000; | |
var b = 6356752.314245; | |
var e2= 0.00669437999019758; | |
var y1 = lat1 * Math.PI / 180; | |
var x1 = lon1 * Math.PI / 180; | |
var y2 = lat2 * Math.PI / 180; | |
var x2 = lon2 * Math.PI / 180; | |
var y_ave = (y1 + y2) / 2; | |
var y_diff = y1 - y2; | |
var x_diff = x1 - x2; | |
var w = Math.sqrt(1 - e2 * Math.pow(Math.sin(y_ave), 2)); | |
var n = a / w; | |
var m = a * (1 - e2) / Math.pow(w, 3); | |
return Math.sqrt(Math.pow(y_diff * m, 2) + Math.pow(x_diff * n *Math.cos(y_ave), 2)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment