Google Maps Remember Last location
Last Updated 16th December 2008
Using GMap2.savePosition() and GMap2.returnToSavedPosition() |
Using cookies via Javascript |
|||
Description
A demonstration of two methods for saving and reloading a position on a Google Map. This allows a preset location to be brought up quickly without the user spending time remembering or panning and zooming to the position. A position is assumed to be a combination all all the following:
- Latitude
- Longitude
- Level of Zoom
Using GMap2.savePosition() and GMap2.returnToSavedPosition()
How To Use
- Once the map has fully loaded on the page, pan and zoom to find a particular location
- Click Save
- Move the map to somewhere else
- Click Load
- The map should return to its saved state
How it Works
The methods GMap2.savePosition() and GMap2.returnToSavedPosition() are included in the Google Maps API and are very easy to use in the required events.
The code use to call these methods is...
Advantages and Disadvantages
- A: Simple to implement
- A: Does not use cookies
- D: Will not remember if the user leaves the page
Using Cookies
How To Use
- Once the map has fully loaded on the page, pan and zoom to find a particular location
- Click Save
- Move the map to somewhere else
- Click Load
- The map should return to its saved state
- Then try navigating away from this page and then try to load again
How it Works
The code use save and load the location is...
Advantages and Disadvantages
- A: Can save location even if the user leaves the page and comes back
- D: Require extra javascript
- D: Uses cookie which can be blocked or deleted on the client machine
- A: Available for customised expansion i.e. remember additional data such as...
- a name for that saved location
- multiple saved locations
- The map state (Map /Satellite / Hybrid)
Version History
- Version 1 (16/12/2008) - You are here
Previous Comments For This Page
Hi
Would it be that hard to enable the user to save multiple maps and load them at another vist
By Lee on 29/06/2009Hi there, thanks for your help earlier. I have 2 questions
1. When the page loads the map will only work properly if you with the reset icon, otherwise the drag and zoom options seem really sensitive. Any ideas. Page can be found here http://www.vineyardroads.co.nz/cookieresults.php?id=1&tastings=0&Submit=Search
2. On this site I have one map page used for 17 regions, if I use your code, it remembers the location for 1 map and if you choose another region it loads up the previous maps location. How do I save multiple cookies for each location (or save multiple sets of data in the same cookie?)
Thanks in advance
Steven
By Steven on 29/06/2009Try using the event http://code.google.com/apis/maps/documentation/reference.html#GMap2.moveend to call the Save function.
By Daft Logic on 13/02/2009Hi there, great work with maps, I am wanting to do the same, but dont want to have the user clicking save buttons. Is there a way for the cookie to be updated verytime the maps is zoomed or moved? So if the user navigates away, they can come back to the same place
Cheers
By Steven on 11/02/2009
Add your own comment below and let others know what you think: