Solved

Converting Longitude and Latitude to Google Image Tiles Javascript

Posted on 2013-06-19
7
350 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
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…

757 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

22 Experts available now in Live!

Get 1:1 Help Now