how do I get the bounds of a static google map?

2019-04-12 08:16发布

问题:

I am trying to plot geo coordinates (lat/lon) on an image I retrieve via Googles static Map API. I want to do this offline directly on the image via Ruby because I want to plot about 20,000 coordinates.

However, for this task, I need to specify the corner (top left & bottom right) coordinates. here is the link to my map: http://maps.google.com/staticmap?center=51.0,10.0&zoom=6&size=640x640&format=png&sensor=false

How can I get coordinates for the top left and bottom right corners of this map?

Thanks in advance :)

PS: My code for Lat/Lon -> X/Y is this for now:

def get_img_coords(lat, lon, w, h, lat_ul, lon_ul, lat_lr, lon_lr)
  { :x => (lon + lon_ul) * (w / (lon_lr-lon_ul)),
    :y => (lat + lat_ul) * (h / (lat_lr-lat_ul)) }
end

... assuming mercator projection of course.

回答1:

I ran into this problem before. Last time I checked (which was a bit over a year ago), the Maps API encoded most of its information via Geohashing. I suggest you start by looking at the Wikipedia page for it, and see this other stackoverflow question, which appears to have a Java implementation of what you want.



回答2:

The method described in this answer to another StackOverflow question worked perfectly for me. Also, the code Marcelo has provided is mostly straightforward to translate from JavaScript into another language, e.g. Python.