Restoring google map state when navigating back to map page

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?

  • google.maps.places is undefined
  • IE6: Doesn't load Google Maps API v3
  • Google maps API key works on a site, but does not work on an other site though referer for the other site is added
  • Google Maps JS v3 - detached DOM tree - memory leak?
  • google maps api script does load due to content security policy
  • How to remove a MapType from google map using Google Maps Javascript V3 API?
  • How to get google place api results from autocomplete.getPlace()
  • Clearing balloons google maps: Uncaught ReferenceError: markers is not defined
  • Remove grid lines on Google Maps caused by zoom
  • Google Map jQuery - getting LatLng from mouse click
  • Google Maps V3: Check if marker is present on map?
  • You have included the Google Maps API multiple times on this page
  • One Solution collect form web for “Restoring google map state when navigating back to map page”

    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.