3
votes

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.

2
map link problem: "This web site needs a different Google Maps API key."jpwco
Have been looking at this one for a bit, tried a few things with public code that didn't work. I think the secret lies in taking the tile resolution at a given zoom level, moving from the known centre a known pixel distance to the edge, then computing the reverse EPSG:4326 projection to find the corner coordinates.captainpete

2 Answers

1
votes

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.

0
votes

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.