Skip to main content

geo_to_tile

Function geo_to_tile 

Source
pub fn geo_to_tile(geo: &GeoCoord, zoom: u8) -> TileCoord
Expand description

Convert a geographic coordinate to a fractional tile coordinate at the given zoom.

Uses the standard Mercator tile formula:

x = (lon + 180) / 360 * 2^zoom
y = (1 - ln(tan(lat) + sec(lat)) / pi) / 2 * 2^zoom

The input must be within the Web Mercator valid range (latitude approximately +/-85.06 degrees). Latitudes at or beyond the poles produce infinite or NaN y values.