I have a Google map with markers which link through to other pages. If I click one of these markers, then decide to go back to the map page, the map position, zoom level, etc. is reset. Is there a simple way to restore the map to the state it was left at?
Asked
Active
Viewed 398 times
1 Answers
0
The easiest and safest way to do this is to take the state you care about preserving (such as zoom, map centre, map type) and storing it somewhere semi-permanent in the browser. Depending on what browsers you want to support, your options are:
- Cookies (JS access via
document.cookie
) - HTML5 local storage (modern browsers)
- URL hash tags (add
#zoom=4&...
to the end of the page, kinda ugly, not really suitable) - HTML5 history API (probably not suited either)
Cookies are probably the best way forward, maybe combined with local storage.
Note that it's probably the browser unload
event causing this issue. However, it looks like the API itself is registering this event at the moment – so you can't really avoid it.
-
Thanks Dave. I think it will be cookies as I have to continue supporting IE7. – Donny Hammell Feb 16 '12 at 10:02