Solved

Converting Longitude and Latitude to Google Image Tiles Javascript

Posted on 2013-06-19
7
354 Views
Last Modified: 2013-06-20
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)
0
Comment
Question by:ALASKASTREETMASTER
  • 4
  • 3
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39261035
Do it work with : zoomLevel = 1 ?

Try this :
function getXYfromLatLon(lat, lon, zoomLevel) { 
	var lon = 180.0 + lon; 
	var x = Math.floor( (lon / 360.0) * 131072 ); 
	var zoomLevel = Math.pow(2, zoomLevel); 
	x = 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 = y / zoomLevel;  
	return new Array(x,y); 
}

Open in new window

0
 

Author Comment

by:ALASKASTREETMASTER
ID: 39261052
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.2598114013671875.

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/
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39261064
using (from the site) :
var lon = -122; var lat = 37; var zl =3;

I get : [2639, 6377]

It is a wrong result?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:ALASKASTREETMASTER
ID: 39261080
How did you run the routine? Web Page?
I have only tried it in Acrobat. Which is where I need it to work.
Thanks.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39261101
Check here : http://jsfiddle.net/5R6V8/
And check attachment
NOTICE.pdf
0
 

Author Comment

by:ALASKASTREETMASTER
ID: 39261128
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.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39261269
Check this : http://jsfiddle.net/GPS66/4/

I used zoomLevel = 17-zoomLevel
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now