Skip to content

Instantly share code, notes, and snippets.

@zhm
Created September 21, 2011 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhm/1232293 to your computer and use it in GitHub Desktop.
Save zhm/1232293 to your computer and use it in GitHub Desktop.
function long2tileX(lon, zoom) {
return Math.floor((lon + 180.0) / 360.0 * Math.pow(2.0, zoom));
}
function lat2tileY(lat, zoom) {
var googleY = Math.floor((1.0 - Math.log(Math.tan(lat * Math.PI/180.0) + 1.0 / Math.cos(lat * Math.PI/180.0)) / Math.PI) / 2.0 * Math.pow(2.0, zoom));
var tmsY = Math.pow(2.0, zoom) - googleY - 1;
return tmsY;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment