Skip to content

Instantly share code, notes, and snippets.

@lucasprogamer
Last active February 10, 2023 17:45
Show Gist options
  • Save lucasprogamer/a299478e5d9d9bab224c538a18fc7ae0 to your computer and use it in GitHub Desktop.
Save lucasprogamer/a299478e5d9d9bab224c538a18fc7ae0 to your computer and use it in GitHub Desktop.
Manhatan calc in js
function distance(lat, long, lat1, long1, useManhatan) {
var r = Math.sqrt;
var o = Math.cos;
var l = Math.sin;
var p = Math.PI;
var m = Math.round;
var earthCurve = 6371;
var manthatanConst = 1.309;
var latresult = (lat1 - lat) * p / 180;
var longr = (long1 - long) * p / 180;
var distance = l(latresult / 2) * l(latresult / 2) + o(lat * p / 180) * o(lat1 * p / 180) * l(longr / 2) * l(longr / 2);
var result = 2 * Math.atan2(r(distance), r(1 - distance));
var c = earthCurve * result;
return useManhatan ? (m(10 * (manthatanConst * c)) / 10).toFixed(1) : (m(10 * c) / 10).toFixed(1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment