apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.27k stars 382 forks source link

map is not correctly centered if turned on after page load #420

Closed SheetalShah closed 10 years ago

SheetalShah commented 10 years ago

I have a strange behaviour. I display the map only if a checkbox is checked. When the user checks the box, i addMarker in .js using the below Gmaps.store.markers = Gmaps.store.handler.addMarkers(<%= raw @json %>, { draggable: false, }); Gmaps.store.handler.resetBounds(); Gmaps.store.handler.bounds.extendWith(Gmaps.store.markers); Gmaps.store.handler.fitMapToBounds(); Gmaps.store.handler.getMap().setZoom(10);.

the marker appears at the correct location. however, the issue is the map is not correctly centers so, the marker appears outside the visible area.

however, if the map is display when its first loaded, it correctly centers on all markers that i replace it with.

apneadiving commented 10 years ago

Please ask questions on stackoverflow

Sent from my iPhone

On 14 janv. 2014, at 07:36, SheetalShah notifications@github.com wrote:

I have a strange behaviour. I display the map only if a checkbox is checked. When the user checks the box, i addMarker in .js using the below Gmaps.store.markers = Gmaps.store.handler.addMarkers(<%= raw @json %>, { draggable: false, }); Gmaps.store.handler.resetBounds(); Gmaps.store.handler.getMap().centerOn({ lat: @lat, lng: @lng }); Gmaps.store.handler.bounds.extendWith(Gmaps.store.markers); Gmaps.store.handler.fitMapToBounds(); Gmaps.store.handler.getMap().setZoom(10);.

the marker appears at the correct location. however, the issue is the map is not correctly centers so, the marker appears outside the visible area.

however, if the map is display when its first loaded, it correctly centers on all markers that i replace it with.

— Reply to this email directly or view it on GitHub.