Last active
August 29, 2015 14:03
-
-
Save caged/47129c3c0ba560010d8d to your computer and use it in GitHub Desktop.
lat/lon to tile number from http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#ECMAScript_.28JavaScript.2FActionScript.2C_etc..29
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function long2tile(lon,zoom) { | |
return (Math.floor((lon+180)/360*Math.pow(2,zoom))); | |
} | |
function lat2tile(lat,zoom) { | |
return (Math.floor((1-Math.log(Math.tan(lat*Math.PI/180) + 1/Math.cos(lat*Math.PI/180))/Math.PI)/2 *Math.pow(2,zoom))); | |
} | |
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)))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment