views:

245

answers:

3

I'd like a way to obtain a static map (an image file) based on two coordinates representing the desired rectangle or area.

Suggestions?

+2  A: 

Yep. Google has a Static Maps API which does exactly this. It is basically just a URL with the latitude, longitude and zoom level passed as parameters (and a whole lot of other variables). You can read about it in the Google Maps API documentation.

Here is an example of what you can do:

From the URL:

http://maps.google.com/staticmap?center=40,26&zoom=1&size=150x112&maptype=satellite&key=ABQIAAAAgb5KEVTm54vkPcAkU9xOvBR30EG5jFWfUzfYJTWEkWk2p04CHxTGDNV791-cU95kOnweeZ0SsURYSA&format=jpg

Edit: As per your comment. The closest I can get to a square form 30,40 lat 60,70 lng is center 35,65 zoomlevel 6. I have created an example 400x400 image. Just change the key in the following URL to get your static map image:

http://maps.google.com/staticmap?center=35,65&zoom=6&size=400x400&key=<your key here>&format=jpg

Thanks ChrisB for pointing out the span param (I hadn't seen that before). I updated my example with the span version of the URL:

http://maps.google.com/staticmap?center=35,65&span=5,5&size=400x400&key=<your key here>&sensor=false

As you can see from the example, this generates the same zoom level as the origional URL, but provides a much easier way of getting there (rather than adjusting the zoom by hand and checking the edges).

As Chris points out the granularity of the zoom levels will can only approximate the edges of the map. If you require a closer approximation, I can only suggest adjusting the size of the static image map to try and get closer to the your boundary latitude/longitude.

Cannonade
so how do i ensure i only get the area between lng 70 lat 40, lng 60 lat 30?
carrier
You need to play around with the zoom level. Set the center point at lng 75, lat 35 and then adjust the zoom until you are happy with the image you get back.
Cannonade
You will need a Google Maps API key to do this (it is part of the URL) ... I'll play around with the zoom and see if I can get you the URL you need.
Cannonade
+2  A: 

If you need the map to precisely fit a particular area, it is unlikely that you'll be able to do it because most of the map API's have pre-designated zoom levels, and there probably won't be a zoom level that will allow you to perfectly fit your area.

However, if you just need to get close, the Google Static Maps API provides a method to specify a viewport, eliminating the need to set the zoom level yourself. All you need is the center point and the span. If you want the area from SW(30,70) to NE(40,60) the center would be (35,65) and the span would be (5,5).

http://maps.google.com/staticmap?center=35,65&span=5,5&size=400x400&key=MAPS_API_KEY&sensor=false

Note that you'll get different results depending on the requested image size.

Chris B
A: 

http://wiki.openstreetmap.org/wiki/MapOf

However this is about OpenStreetMap

Igor Shubovych

related questions