放大gmap4rails中的特定区域 [英] zoom in to particular region in gmap4rails

查看:114
本文介绍了放大gmap4rails中的特定区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何放大gmaps4rails中的特定坐标。假设在我的应用程序的索引页面上,我想显示所有用户的地址,但是最初地图应该关注于美国和某个缩放级别。


解决方案

在你的gmaps调用之后:

 <%content_for:scripts do%> 
< script type =text / javascriptcharset =utf-8>
Gmaps.map.callback = function(){
setTimeout(function(){
var bounds = new google.maps.LatLngBounds(new google.maps.LatLng(10,0), new google.maps.LatLng(0,10));
Gmaps.map.serviceObject.panToBounds(bounds);
},50);
}
< / script>
<%end%>

缩放将根据传递的界限进行调整,否则请添加:

  Gmaps.map.serviceObject.setZoom(your_int_value); 






更简洁的方法是使用由google:

  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);
}
});


How to zoom in to a particular coordinates in gmaps4rails. suppose at the index page of my application i want to show addresses of all users but want that initially the map should focus on USA and with a certain zoom level

Thanks in advance

解决方案

After your gmaps call:

<% content_for :scripts do %>
    <script type="text/javascript" charset="utf-8">
      Gmaps.map.callback = function() {
        setTimeout(function() {
          var bounds = new google.maps.LatLngBounds(new google.maps.LatLng(10, 0), new google.maps.LatLng(0, 10));
          Gmaps.map.serviceObject.panToBounds(bounds);
       }, 50);
      }
    </script>
<% end %>

The zoom will be adapted to the bounds passed, otherwise add:

Gmaps.map.serviceObject.setZoom(your_int_value);


A cleaner approach is to use the callback provided by google:

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);
   }
});

这篇关于放大gmap4rails中的特定区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆