Get boundary coodinate from Google static map

We can use the following url to create one static google map image:
"http://maps.google.com/staticmap?center=" + lat + "," + lng + "&format="
+ format + "&zoom=" + zoom + "&size=" + width + "x" + height + "&key=" + apiKey;

How could know the boundary coordinate information of this image?
What we know:
1. center latitude/longitude point where map centered on
2. map image's total pixel width/height
3. map zoom level.

Here is the array of pixelsperLonDegree[zoom_level] for each map type.
For map types other than Katrina, the values are:

zoom pixelsPerLonDegree
==== ==================
0 93206.75555555556
1 46603.37777777778
2 23301.68888888889
3 11650.844444444445
4 5825.422222222222
5 2912.711111111111
6 1456.3555555555556
7 728.1777777777778
8 364.0888888888889
9 182.04444444444445
10 91.02222222222223
11 45.51111111111111
12 22.755555555555556
13 11.377777777777778
14 5.688888888888889
15 2.8444444444444446
16 1.4222222222222223
17 0.7111111111111111

So if your map is 1000 pixels wide and your zoom level is 8, the width of the map would be 1000/364.0888888888889 degrees of longitude (2.74658 degrees). Add and subtract half that to the longitude of the centre to get the longitude bounds.

Java code:

  1. /**
  2. *
  3. * @param centerlat
  4. * @param centerlon
  5. * @param room
  6. * @param imagew
  7. * @param imageh
  8. * @return latBottom, lonLeft, latTop, lonRight (left-bottom and right-top point lat /lon)
  9. */
  10. public static double[] getCorner(double centerlat, double centerlon, int zoom, int imagew, int imageh){
  11. double lonspan = imagew / pixelsPerLonDegree[zoom];
  12. double latspan = imageh / pixelsPerLonDegree[zoom];
  13.  
  14. double lonRight = centerlon + lonspan/2;
  15. double lonLeft = centerlon - lonspan/2;
  16.  
  17. double latTop = centerlat + latspan/2;
  18. double latBottom = centerlat - latspan/2;
  19.  
  20. return new double[]{latBottom, lonLeft, latTop, lonRight};
  21. }

JavaScript code:

  1. var cent = map.getCenterLatLng()
  2. var longSpan = map.container.clientWidth/map.getCurrentMapType().pixelsPerLonDegree[map.getZoomLevel()];
  3. var xRight = cent.x + (longSpan/2);
  4. var xLeft = cent.x - (longSpan/2);
  5.  
  6. var cosRadLat = Math.cos(cent.y*Math.PI/180);
  7. var latSpan = map.container.clientHeight*cosRadLat/map.getCurrentMapType().pixelsPerLonDegree[map.getZoomLevel()];
  8. var xTop = cent.y + (latSpan/2);
  9. var xBot = cent.y - (latSpan/2);

Other zoom scale info:
=================================
Zoom level 0 1:20088000.56607700 meters
Zoom level 1 1:10044000.28303850 meters
Zoom level 2 1:5022000.14151925 meters
Zoom level 3 1:2511000.07075963 meters
Zoom level 4 1:1255500.03537981 meters
Zoom level 5 1:627750.01768991 meters
Zoom level 6 1:313875.00884495 meters
Zoom level 7 1:156937.50442248 meters
Zoom level 8 1:78468.75221124 meters
Zoom level 9 1:39234.37610562 meters
Zoom level 10 1:19617.18805281 meters
Zoom level 11 1:9808.59402640 meters
Zoom level 12 1:4909.29701320 meters
Zoom level 13 1:2452.14850660 meters
Zoom level 14 1:1226.07425330 meters
Zoom level 15 1:613.03712665 meters
Zoom level 16 1:306.51856332 meters
Zoom level 17 1:153.25928166 meters
Zoom level 18 1:76.62964083 meters
Zoom level 19 1:38.31482042 meters

==============================
respective map scales:

1:2250 = z17
1:4500 = z16
1:9000 = z15
1:23000 = z14
1:46000 = z13
1:93000 = z12
1:188000 = z11
1:350000 = z10
1:725000 = z9
1:1500000 = z8

Ref:
http://laudontech.com/GISBlog/?p=28
http://groups.google.com/group/google-maps-api/browse_thread/thread/6ff83431273c6adb/5c572f7cbd3485c0


Blog

评论

Re: Get boundary coodinate from Google static map

You've ralely captured all the essentials in this subject area, haven't you?

Re: Get boundary coodinate from Google static map

I'm sorry...in what part of the world does this work...???
I have a map 240w/291h
latitude:46.758232449510366
longitude:23.591766357421875
zoom level:16

if you try this data and get a result please reply.I am very curious.
thanx