1

I'm trying to save the bounds of my google map as it moves in local storage so that I can reopen the app and have the map at the exact same place. However, every time the page reloads, it seems to be centered on the same point, but slightly zooms out each time.

Is there a bug that is causing this in their bounds calculations, or am I utilizing their data wrong.

Here is a JSFiddle: http://jsfiddle.net/Hu65m/

Zoom in on a location, click run again and it will reload, but being a little zoomed out.

map.fitBounds(getBounds(), {
    animate: false
});

google.maps.event.addListener(map, 'idle', function() {
    console.log("idle");
    saveBounds(map.getBounds());
});
Eli White
  • 1,014
  • 1
  • 10
  • 20
  • 1
    possible duplicate of [goole maps API 3 zooms out on fitBounds](http://stackoverflow.com/questions/8170023/goole-maps-api-3-zooms-out-on-fitbounds) – Dr.Molle Dec 22 '13 at 08:34
  • Thank you kind internet citizen, I searched for a while on Google but that didn't show up. – Eli White Dec 22 '13 at 08:40

1 Answers1

1

fitBounds will make sure your bounds fit on the map, which means it will be bigger than the actual bounds.

You can do it by saving your map center and zoom level instead. Please check http://jsfiddle.net/upsidown/erV6Q/

var center = map.getCenter();
var zoom = map.getZoom();

localStorage.mapCenter = JSON.stringify(center);
localStorage.mapZoom = zoom;
MrUpsidown
  • 21,592
  • 15
  • 77
  • 131