I used Google API version 2 in my previous assignment. There I had used map.savePosition()
to save the current position of map and map.returnToSavedPosition()
to restore to the saved position. I have searched for the equivalent in api version 3 documentation but could not find relevant results. And if I use map.savePosition()
now with api-3, javascript error tells "map.savePosition is not a function".
Can someone please tell me what are the ways to save and restore the position of Google Map in API 3 ?
As said above, there's no similar function in V3. It's really easy to implement yourself.
Here's one way:
var previousPosition;
function savePosition(map) {
previousPosition = map.getCenter();
}
function returnToSavedPosition(map) {
if (previousPosition) {
map.panTo(previousPosition); // or setCenter
}
}
... then just call it like:
savePosition(map);
Simple, huh?
v3 doesn't have a savePosition() function. You need to use getCenter() and getZoom() to retrieve the current position and then restore that position with setCenter() and setZoom().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With