Created
January 27, 2024 13:40
-
-
Save yevmoroz/778ce231b42833fe4de3b55771f06335 to your computer and use it in GitHub Desktop.
bounding rectangle box
This file contains 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
const radToDeg = (v) => { | |
return (v * 180) / Math.PI; | |
}; | |
const degToRad = (v) => { | |
return (v * Math.PI) / 180; | |
}; | |
export const getBoundBox = (lat, lon, rangeInMeters = 10) => { | |
const latRad = degToRad(lat); | |
const lonRad = degToRad(lon); | |
const d = rangeInMeters / 6371000; | |
const minLat = latRad - d; | |
const maxLat = latRad + d; | |
const minLon = lonRad - d / Math.cos(latRad); | |
const maxLon = lonRad + d / Math.cos(latRad); | |
return [ | |
[radToDeg(minLat), radToDeg(minLon)], | |
[radToDeg(maxLat), radToDeg(maxLon)], | |
]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment