Skip to content

Instantly share code, notes, and snippets.

@Bigismall
Forked from spite/gist:051604efd1d971ab4b6ef1bc1ae2636e
Last active June 25, 2021 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bigismall/afa5366cc9c65ac3b4594f4580fc4741 to your computer and use it in GitHub Desktop.
Save Bigismall/afa5366cc9c65ac3b4594f4580fc4741 to your computer and use it in GitHub Desktop.
zoom - lat -lon to mapzen/tilezen tile
function getTileFromLatLon(zoom, lat, lon) {
const width = Math.pow(2, zoom);
const height = Math.pow(2, zoom);
const latRad = (lat * Math.PI) / 180;
const x = ~~((width * (lon + 180)) / 360);
const y = ~~(((1 - Math.asinh(Math.tan(latRad)) / Math.PI) / 2.0) * height);
return {zoom, x, y};
}
@Bigismall
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment