Struggling to get Northeast , Southwest long/lat of an each tile

119 views
Skip to first unread message

vali...@gmail.com

unread,
Feb 7, 2011, 6:51:41 PM2/7/11
to Google Maps JavaScript API v3
Hello, I'm searching whole night for this, and i cannot get it still..
I want to get long/lat from NE,SW for each tile that loads , anyone
can help me out? I have parameters for X,Y,Z , how can i find out the
coords

Martin

unread,
Feb 7, 2011, 11:49:02 PM2/7/11
to Google Maps JavaScript API v3

vali...@gmail.com

unread,
Feb 8, 2011, 4:18:28 AM2/8/11
to Google Maps JavaScript API v3

vali...@gmail.com

unread,
Feb 8, 2011, 4:34:30 AM2/8/11
to Google Maps JavaScript API v3
var pixelcoord1={x:coord.x*256,y:coord.y*256,z:zoom} ;
var pixelcoord2={x:(coord.x+1)*256,y:(coord.y+1)*256,z:zoom} ;
var worldcoord1={x:pixelcoord1.x/Math.pow(2,zoom),y:pixelcoord1.y/
Math.pow(2,zoom)};
var worldcoord2={x:pixelcoord2.x/Math.pow(2,zoom),y:pixelcoord2.y/
Math.pow(2,zoom)};

now i need to convert world coordinates in lat/long or there is
another step between this?

vali...@gmail.com

unread,
Feb 8, 2011, 4:42:46 AM2/8/11
to Google Maps JavaScript API v3
Ok i think i got it , here is the code in case someone needs it...


var pixelcoord1={x:coord.x*256,y:coord.y*256,z:zoom} ;
var pixelcoord2={x:(coord.x+1)*256,y:(coord.y+1)*256,z:zoom} ;
var worldcoord1 = new google.maps.Point(pixelcoord1.x/
Math.pow(2,zoom),pixelcoord1.y/Math.pow(2,zoom));
var worldcoord2 = new google.maps.Point(pixelcoord2.x/
Math.pow(2,zoom),pixelcoord2.y/Math.pow(2,zoom));

var projection = map.getProjection();
var sw = projection.fromPointToLatLng(worldcoord1);
var ne = projection.fromPointToLatLng(worldcoord2);

bratliff

unread,
Feb 8, 2011, 11:41:01 AM2/8/11
to Google Maps JavaScript API v3
On Feb 7, 11:51 pm, "valium...@gmail.com" <valium...@gmail.com> wrote:
The basic math is contained in:

http://www.polylib.us/adjust.js

The lower left corner of your tile is:

X<<(21-Z)
((Y+1)<<(21-Z))-1

The upper right corner of your tile is:

((X+1)<<(21-Z))-1
Y<<(21-Z)

Use XToL & YToL to obtain Longitude & Latitude respectively.

vali...@gmail.com

unread,
Feb 8, 2011, 3:38:12 PM2/8/11
to Google Maps JavaScript API v3
i think i tried this but i couldnt get it to work...

bratliff

unread,
Feb 9, 2011, 10:54:50 AM2/9/11
to Google Maps JavaScript API v3
OOPS. The shift amounts are wrong. Your X & Y are tile numbers
rather than pixel offsets.

Try:

The lower left corner of your tile is:

X<<(29-Z)
((Y+1)<<(29-Z))-1

The upper right corner of your tile is:

((X+1)<<(29-Z))-1
Y<<(29-Z)

Sorry

Reply all
Reply to author
Forward
0 new messages