Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have multiple tile sources generated using gdal2tiles I'd like to present on the same map. So when presenting a tile I need to determine which source to serve it up from, checking against the bounds.

Anyone know how to calculate the lat lon bounds for a single tile based purely on zoom, x, and y (from the file structure generated by gdal2tiles)? BTW: I'm using Google Maps API v3 in case there's a need to call some functionality from the API to help with calculations.

The reason I'm restricted to purely zoom, x, and y is because the tiles aren't just getting called by an overlay on the map but also some custom print functionality that allows printing outside of the map.

Thanks in advance for any help or suggestions anyone has.

Cheers, Gavin

share|improve this question

1 Answer 1

up vote 9 down vote accepted

This question was already answered in Maptiler User Group where you asked too.

Hi Gavin,

the math is described at:

including the source code for command line utility and an online demonstration.

It is also pretty simple math:

function tile2long(x,z) { return (x/Math.pow(2,z)*360-180); }
function tile2lat(y,z) { var n=Math.PI-2*Math.PI*y/Math.pow(2,z);
return (180/Math.PI*Math.atan(0.5*(Math.exp(n)-Math.exp(-n)))); }

Please be sure you understand difference between XYZ/Google vs TMS in y axis (discussed several times in this mailing list).

Google Maps API V3 gives you the required functions too via .fromPointToLatLng() of map.getProjection().

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.