how to set a zoom level using Gmap4rails?

佐手、 提交于 2019-12-08 09:54:56

问题


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)


来源:https://stackoverflow.com/questions/19954579/how-to-set-a-zoom-level-using-gmap4rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!