Skip to content

Instantly share code, notes, and snippets.

@slaypni
Created November 2, 2011 09:11
Show Gist options
  • Save slaypni/1333234 to your computer and use it in GitHub Desktop.
Save slaypni/1333234 to your computer and use it in GitHub Desktop.
calculate Hubeny's distance from Geolocation
// 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