I need to take data about a dynamic Google map and create a static Google map from it using API V3
Asked Answered
N

2

11

What I really want to do is to allow a user to create a map with google maps and save the image. I have attempted a work around that does this by using the google maps api V3 and also the static maps api.

The user can use the dynamic google map to scroll, zoom, etc and find a map they like. The user should then press a button which extracts the data from the google map (center, zoom level, etc) which sends the query to the static google map api. The static google map api will then return the image which can be saved.

I have this all working* except it doesn't always work. Sometimes the images returned by static google maps will be exactly what the user sees in the dynamic map. Other times the image may be off by a few meters (I believe this is because the dynamic google map api uses greater precision for longitude and latitude than the static api), or even thousands of kilometers (I have no idea why this happens). The images are usually off the greater the zoom level is (because of the precision differences).

I want to know if anyone has tried converting a dynamic map to a static map and came up with a non-buggy solution, or if there is a better solution that works.

Neuroticism answered 24/11, 2011 at 19:6 Comment(10)
I created a little JSFiddle to test this out a bit. You can view it here - jsfiddle.net/brettdewoody/3kDbx/10 Move the map around, zoom in/out, change the map type, then click the 'Get Static Map' button in the bottom left. That should replace the Google Map with an exact same static image map. So far it appears to always show the same view. Can you find some specific cases that don't show the same view?Windtight
Is it possible that you're requesting too large of a Static Map? The maximum for the free version of the Static Map API is 640x640 pixels. If you request larger than that I think it'll crop your map.Windtight
No it isn't a size issue. Yours has the same problem. I tried zooming in near the bottom of South Africa (zoom a lot). The dynamic map showed a road, when I clicked the static map link it showed the ocean.Neuroticism
I can't reproduce the issue, zooming around the south of South Africa in various places. Is there a specific city/town and street? Also, you mentioned having users save the image. Note that the terms of service for both APIs prohibit this: code.google.com/apis/maps/terms.html. Section 10.1.3.Muraida
This is very odd. I can reproduce the problem about 1 out of every 20 times when looking at various spots in both South America and South Africa. I took screen shots of locations that didn't work and then revisited the problem spots. The second time I went there the static map was correct. One spot that didn't work (but worked the next time I went there) was Mejicana and Arauco streets in Chile. I was zoomed in all the way. The map returned was all blue. When I tried to recreate this the static map did work. I can't explain it.Neuroticism
I thinks Brett DeWoody's code is working fine for me !!Delft
My guess, from (bad) experience, is that you're probably dropping the sign of your lat/long or similar math issue. Verify that the lat/long you're sending to the static maps API is the one the user is seeing - my bet is you're losing some info along the way.Eerie
Try using the above jsfiddle solution to get a map showing Cyprus. I have tried this test 5 times now, and the static map returned is very far off from what is shown for the dynamic map. Can anyone else verify this bug?Neuroticism
@Eerie - good thought, though if that were the case (Abs or some such) then it would fail consistently on one side of the equator/dateline.Defector
@Neuroticism Did you come right with this issue? I am facing the same issue, where for certain overlays its off and for others its correct. I copied the lat lng array into a csv and imported it into google and there it was correct. So am quite conused.Glaucescent
D
1

"...I believe this is because the dynamic google map api uses greater precision for longitude and latitude than the static api..."

AFAIK In the both the Google Maps V3 and the Static Maps api Latitudes and longitudes have a precision to 6 decimal places. Precision beyond the 6 decimal places is ignored. This seems to be the point made in both these docs, athough the one pertaining to the Maps api does state (my emphasis).

"With the current zoom capabilities of Google Maps, you should only need 6 digits of precision after the decimal"

Static http://code.google.com/apis/maps/documentation/staticmaps/#Usage

Regular http://code.google.com/apis/maps/articles/phpsqlajax_v3.html

Without seeing the code you are using it is hard to say what the root issue of your problem is though.

Defector answered 17/2, 2012 at 10:11 Comment(0)
T
0

This wizard makes for a really good start. It lets users build up a map, and then converts everything (overlays, etc) into a suitable Static Maps URL.

It uses the Maps API V2, though, which is deprecated. You'll want to be using the V3 Maps API.

Another wizard that does something similar is the Styled Maps Wizard. It doesn't have any overlays, but lets the user style the map, re-center, specify zoom, and then generate the Styled Maps URL.

Tulatulip answered 12/2, 2012 at 13:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.