Solved

# Converting Longitude and Latitude to Google Image Tiles Javascript

Posted on 2013-06-19

I am trying to get this code to work in the Acrobat JavaScript api. I keep getting 0,0 as the result. Any help would be appreciated.

lat = 65.06518345;

lon = -146.09069824;

zoomLevel = 17;

function getXYfromLatLon(lat, lon, zoomLevel) {

var lon = 180.0 + lon;

var x = Math.floor( (lon / 360.0) * 131072 );

/* 2^17 = 131072 */

x >>= zoomLevel;

var lat = lat / 180.0 * 3.1415926;

var y = Math.PI - 0.5 * Math.log((1+Math.sin(lat))/(1-Math.sin(lat)));

y = Math.floor( (y / 2 / Math.PI) * 131072 );

y >>= zoomLevel;

return new Array(x,y);

}

getXYfromLatLon(lat, lon, zoomLevel)