【问题标题】:Google Map doesn't zoom in to the bounds of the filtered/new markers using jquery-ui-map谷歌地图不使用 jquery-ui-map 放大过滤/新标记的边界
【发布时间】:2012-05-29 19:24:33
【问题描述】:

我将this jQuery plugin 用于我的Google 地图

我有一个小表格,用于过滤地图上的标记。

标记是使用插件的$('#map_canvas').gmap('addMarker', {...}) 函数创建的,使用该函数创建标记时我可以传递的属性之一是bounds:true。它的作用是 - 当所有标记都创建并显示后,地图应该放大到地图上所有标记的边界。

问题是 - 出于某种原因,当我过滤时(按 提交 按钮),地图没有放大到新的标记。它只是停留在原来的位置。

这是为什么呢?如何使其放大到新标记的边界?

jQuery:

// when map is initialized, plot all the markers    
$('#map_canvas').gmap(mapOptions).bind('init', function(){
                        $.getJSON('myscript.php', function(json){
                            var theMarkers = json;
                            $.each(theMarkers, function(i, val) {
                                $('#map_canvas').gmap('addMarker', { 'position': new google.maps.LatLng(val.Lat, val.Lng), 'bounds':true, 'icon':'myicon.png' } ).click(function(){                             
                                    $('#map_canvas').gmap('openInfoWindow', { 'content': '<h1>'+val.Name+'</h1>'+'<h2 style="color: grey">'+val.Address+'</h2><p style="color: green">'+val.Telephone+'</p>' }, this);
                                });                     
                            });
                        }); 

                    });

                    // upon clicking submit button - clear old markers and plot newly filtered ones on the map
                    $('#myform').on('submit', function(e) {
                        $('#map_canvas').gmap('clear', 'markers');
                        e.preventDefault();
                        var myData = $('#myform').serializeArray();
                        $.getJSON('myscript.php', myData, function(json){
                            var theMarkers = json;
                            $.each(theMarkers, function(i, val) {
                                $('#map_canvas').gmap('addMarker', { 'position': new google.maps.LatLng(val.Lat, val.Lng), 'bounds':true, 'icon':'myicon.png' } ).click(function(){                             
                                    $('#map_canvas').gmap('openInfoWindow', { 'content': '<h1>'+val.Name+'</h1>'+'<h2 style="color: grey">'+val.Address+'</h2><p style="color: green">'+val.Telephone+'</p>' }, this);
                                });                     
                            });

                        }); 
                    });

【问题讨论】:

    标签: google-maps google-maps-api-3 jquery-ui-map


    【解决方案1】:
    $('#map_canvas').gmap('set', 'bounds', null);
    

    原来你必须重新设置边界。在绘制/创建标记之前。

    http://code.google.com/p/jquery-ui-map/issues/detail?id=42

    【讨论】:

      猜你喜欢
      • 2012-04-10
      • 1970-01-01
      • 2018-03-22
      • 2012-03-22
      • 2016-11-23
      • 1970-01-01
      • 2021-09-05
      • 2013-07-20
      • 1970-01-01
      相关资源
      最近更新 更多