Using map.getCenter() to identify tiles

In a nutshell what I want to do is to identify the center tile from the result of “map.getCenter()”.

I am building my first OpenStreetMap/OpenLayers application and am using “new OpenLayers.Layer.OSM()” for my map layer. When I request the coordinates of the center using “map.getCenter()” with a zoom level of 10, the resulting longitude/latitude are returned in the form lon=1813763,lat=6155449 (in degrees the center is roughly Lon=16.4° and Lat=48.3°). I have never seen coordinates like this before but on reading up on the “Spheroid Mercator” at http://docs.openlayers.org/library/spherical_mercator.html which states “Any time you see the string “EPSG:4326”, you can assume it describes latitude/longitude coordinates. Any time you see the string “EPSG:900913”, it will be describing coordinates in meters in x/y.”, I assumed that these coordinates are in EPSG:900913. Please correct me if I am mistaken.

After reading about tile naming in http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames it seems I can use the EPSG:900913 X/Y coordinates to ascertain the tile number. However if I use the result of “map.getCenter()” in the URL’s http://tile.openstreetmap.org/10/1813763/6155449.png or http://tah.openstreetmap.org/Tiles/tile/10/1813763/6155449.png I get a “Not Found” message.

I seem to have got myself hopelessly confused and would really appreciate an explanation of what I need to do with the result of “map.getCenter()” in order to use it to identify and download the relevant tile.

I take it you have read this on the wiki http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames. The problem is that tile naming is not based on actual latitude and longitude but by a continuous process of binary cuts of the world in Spherical Mercator. You can see tile names on this slippy map: http://tools.geofabrik.de/map/?type=Geofabrik&lon=-0.20344&lat=51.50392&zoom=9&grid=1.

For doing the same thing with 900913 you need to know the upper and lower bounds of the two co-ordinates. I think longitude is -20,000,000 to 20,000,000, but I latitude is not a convenient round number, but there is more here http://docs.openlayers.org/library/spherical_mercator.html. So if you use these maxextent values as divisors in the tile name calculation with the ESP:900913 co-ordinates you should get the right tile name.