Created
November 9, 2018 14:06
-
-
Save bichotll/27ddd9859b64b2680da873254829a5e7 to your computer and use it in GitHub Desktop.
zoom calculation from lat, long and km scuare
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
function calcLong(lat, long, distance) { | |
var earth = 6378.137, //radius of the earth in kilometer | |
pi = Math.PI, | |
cos = Math.cos, | |
m = (1 / ((2 * pi / 360) * earth)) / 1000; //1 meter in degree | |
return long + (distance * m) / cos(lat * (pi / 180)); | |
} | |
function calcLat(lat, long, distance) { | |
var earth = 6378.137, //radius of the earth in kilometer | |
pi = Math.PI, | |
m = (1 / ((2 * pi / 360) * earth)) / 1000; //1 meter in degree | |
return lat + (distance * m); | |
} | |
function calcPoint(lat, long, distance) { | |
return [ | |
calcLat(lat, long, distance), | |
calcLong(lat, long, distance), | |
] | |
} | |
function calcBounds(lat, long, distance) { | |
let newLat = calcLat(lat, long, distance) | |
let diffLat = lat - newLat | |
let newLong = calcLong(lat, long, distance) | |
let diffLong = long - newLong | |
let points = [ | |
[lat + diffLat, long + diffLong], | |
[lat - diffLat, long - diffLong], | |
[lat + diffLat, long - diffLong], | |
[lat - diffLat, long + diffLong], | |
] | |
return points | |
} | |
lat = 41.01 | |
long = 28.960278 | |
distance = 5343 | |
console.log(calcBounds(lat, long, distance)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment