how to set a zoom level using Gmap4rails?

2019-06-06 04:36发布

问题:

I've just setup a new project following this video http://youtu.be/R0l-7en3dUw. I was wondering how can I set the map zoom level in a project like this. I've looked at the src on github and since in map.coffee there isn't something like zoomTo: (zoomLvl)-> @getServiceObject().setZoom(zoomLvl) I don't have any idea how to do it. So can anyone help me?

I've tried this kind of solution as suggested here (zoom in to particular region in gmap4rails) but with any good result:

Gmaps.map.callback = function() {
   google.maps.event.addListenerOnce(Gmaps.map.getMapObject(), 'idle', function(){
     var bounds = new google.maps.LatLngBounds(new google.maps.LatLng(10, 0), new google.maps.LatLng(0, 10));
     Gmaps.map.serviceObject.panToBounds(bounds);
   }
});

回答1:

first you're mixing methods from v1 and v2. v2 arrived in october 2013, all previous answers wont be helpful.

Gmaps.map.callback is from v1.

in v2, you can do:

#work directly with the google object:
handler.getMap().setZoom(zoom_level)