Hi,

did you solve your problem already?

I am working on a different problem too. But I just started.

I found at least some bugs:


$x = intval(abs($lon_diff * 6378137) / $scaleToPixel);
$y = intval(abs($lat_diff * 6378137) / $scaleToPixel);

My debug-Output for your special lon and lat is:


lon_diff = 0.00011801719665527
lat_diff = -0.0024721025860543
x = intval(abs(0.00011801719665527 * 6378137) / 2.387);
y = intval(abs(-0.0024721025860543 * 6378137) / 2.387);

x = 315
y = 6605

but the tile byself is only 256x256.

I am not sure but I think your lat_diff should be positive? Excelpt the 0,0 of the tile is not top,left but bottom,left?

Good for testing:
http://www.openstreetmap.org/?lat=50.31142830848694&lon=7.553218603134155&zoom=16&layers=M&mlat=50.31142830848694&mlon=7.553218603134155

Even if you took the PHP-code from here: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#PHP
the xtile is wrong.

http://tile.openstreetmap.org/16/34142/22137.png instead of http://tile.openstreetmap.org/16/34143/22137.png.

Check it here: http://tools.geofabrik.de/map/?type=Geofabrik&lon=7.5532186031342&lat=50.311428308487&zoom=16&grid=1

Coach