Skip to content

Instantly share code, notes, and snippets.

@spite
Created June 15, 2021 23:47
Show Gist options
  • Save spite/051604efd1d971ab4b6ef1bc1ae2636e to your computer and use it in GitHub Desktop.
Save spite/051604efd1d971ab4b6ef1bc1ae2636e 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};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment