Function slippy_map_tilenames::tile2lonlat [] [src]

pub fn tile2lonlat(x: u32, y: u32, zoom: u8) -> (f64, f64)

Convert slippy map tile to lon/lat coordinates, at a given zoom.

Arguments

  • x - X tile coordinate
  • y - Y tile coordinate
  • zoom - zoomlevel of the tile

Examples

extern crate slippy_map_tilenames as smt;

fn main() {
    let res = smt::tile2lonlat(4376, 2932, 13); // (12.3046875, 45.460130637921)
    println!("Tile (4376, 2932) at zoom 13: {:?}", res);
}

Unexpected Behavior

The conversion relies on an equation, which does not check on the validity of the data in imput. For this reason, passing non valid tiles for the relative zoomlevel still gets in output a result, albeit meaningless.

Therefore, care should be taken as to the input of the function in order to pass it valid tiles.

Example:

extern crate slippy_map_tilenames as smt;
 
assert_eq!(smt::tile2lonlat(4376, 2932, 0), (1575180.0, -90.0));

Notice how at zoomlevel 0 there is really just a tile, (0, 0), yet the function still calculates a meaningless result.