Skip to main content
100%

lat/lon to tile number from http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#ECMAScript_.28JavaScript.2FActionScript.2C_etc..29

✓ Published0🌍 Public
CCaged
Last edited Jul 4, 2014
Created on Jul 4, 2014

This example demonstrates how to convert geographic coordinates (latitude and longitude) into slippy-map tile numbers, and vice versa, for a given zoom level. It shows the mathematical relationships between raw coordinate pairs and the tile grid system used by web maps like OpenStreetMap. The code defines pure JavaScript functions—`long2tile`, `lat2tile`, `tile2long`, and `tile2lat`—using the `Math` object’s trigonometric and logarithmic methods to perform the projection. No external libraries are used; the logic directly implements the Web Mercator projection formulas, enabling both forward and inverse tile-number calculations. The functions are standalone and ready for integration into tile-based map renderers.

AI-generated description

Similar vizzes