ALASKASTREETMASTER
asked on
Converting Longitude and Latitude to Google Image Tiles Javascript
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.s in(lat)));
y = Math.floor( (y / 2 / Math.PI) * 131072 );
y >>= zoomLevel;
return new Array(x,y);
}
getXYfromLatLon(lat, lon, zoomLevel)
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))
y = Math.floor( (y / 2 / Math.PI) * 131072 );
y >>= zoomLevel;
return new Array(x,y);
}
getXYfromLatLon(lat, lon, zoomLevel)
ASKER
I tried it like you have it also, with many zoom levels It gives weird answers for each zoom level.
7 = 96.453125,266.046875
1 = 6173,17027 ; the tiles #'s are way too big for 1.
17 = 0.0941925048828125,0.25981 1401367187 5.
I am trying to convert the code from this snippet at this site:
http://blogs.infoecho.net/echo/2007/02/05/code-snippet-for-converting-longitude-and-latitude-to-google-image-tiles-uri/
7 = 96.453125,266.046875
1 = 6173,17027 ; the tiles #'s are way too big for 1.
17 = 0.0941925048828125,0.25981
I am trying to convert the code from this snippet at this site:
http://blogs.infoecho.net/echo/2007/02/05/code-snippet-for-converting-longitude-and-latitude-to-google-image-tiles-uri/
using (from the site) :
var lon = -122; var lat = 37; var zl =3;
I get : [2639, 6377]
It is a wrong result?
var lon = -122; var lat = 37; var zl =3;
I get : [2639, 6377]
It is a wrong result?
ASKER
How did you run the routine? Web Page?
I have only tried it in Acrobat. Which is where I need it to work.
Thanks.
I have only tried it in Acrobat. Which is where I need it to work.
Thanks.
ASKER
http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
using the above web page, the tiles should be 1,3 for coordinates 37,-122 at zl 3.
zl 9 should be 89,205 but comes up 41,99 in fiddle.
Not sure what is off.
using the above web page, the tiles should be 1,3 for coordinates 37,-122 at zl 3.
zl 9 should be 89,205 but comes up 41,99 in fiddle.
Not sure what is off.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this :
Open in new window