How to get boundig box coordinates from tile link ? Help please ...

Hi there everybody. :slight_smile:
I’m still quite new to OpenStreetMap.

I’ve got a simple src tag, allowing me to get one simple map tile, at a given zoom level.

Let’s say my test link is this :

<img src="" width="256" height="256">

As I can see, zoom 16 is a folder, the X Index of the Map Tile is a folder, and the Y Index is the actual name of the png file.

Now, the question.
Knowing these parameters : Zoom=16 / X=32742 / Y=21790 / Scale=256
how could I get the coordinates of the bounding box of this particular tile ?
I mean the Min Longitude / Max Longitude and Min Latitude / Max Latitude of this tile ?
Is there some kind of furmula to calculate the coordinates from the values in the link ?

Thanks to anyone able to help.

You will find all your answers here:

OT: It’s an “img”-tag with a “src”-attribute :wink:

Thank you Pieren. :slight_smile:

That’s what I needed.

The “Tile numbers to lon./lat.” pseudo-code, given tile’s X index, Y index and Zoom, returns the coordinate of the Top-Left corner of the tile, which is maximum Lat and minimum Lon.

To get the other 3 points I did as follows :

  • Top-Right corner : (X+1) index, Y index, Zoom
  • Bottom-Right corner : (X+1) index, (Y+1) index, Zoom
  • Bottom-Left corner : (X) index, (Y+1) index, Zoom

If I’d like to know the Center tile’s coordinates I should do as follows, I guess :
LatCenter = LatMin + ( LatMax - LatMin ) / 2
LonCenter = LonMin + ( LonMax - LonMin ) / 2

Another little question :

If I copy image link in my browser on each OSM’s map tile, at different zoom levels, I get links as follows :

What are those “a.”, “b.”, “c.” letters ?

I see that tiles are also available without them in the link :

They are only aliases for, because most browsers restrict their connections per host.

Got it. Thanks. :slight_smile:

Complete Openstreetmap single tile to lat/lon corners conversion

def tile_corners_to_latlon(xtile, ytile, zoom):
    n = 2.0 ** zoom
    lon_deg = xtile / n * 360.0 - 180.0
    lat_rad_nw = math.atan(math.sinh(math.pi * (1 - 2 * (ytile / n))))
    lat_deg_nw = math.degrees(lat_rad_nw)

    lat_rad_se = math.atan(math.sinh(math.pi * (1 - 2 * ((ytile + 1) / n))))
    lat_deg_se = math.degrees(lat_rad_se)

    lat_deg_nw = max(min(lat_deg_nw, 85.0511), -85.0511)
    lat_deg_se = max(min(lat_deg_se, 85.0511), -85.0511)

    top_left = (lat_deg_nw, lon_deg)
    top_right = (lat_deg_nw, lon_deg + (360.0 / n))
    bottom_right = (lat_deg_se, lon_deg + (360.0 / n))
    bottom_left = (lat_deg_se, lon_deg)

    return top_left, top_right, bottom_left, bottom_right