本文介绍了Google地图不会“有机地缩放”当新的标记加载时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有加载XML图形标记的代码,并且我还将它设置为在加载新标记时进行缩放。然而,我不喜欢的是,缩放发生在瞬间,并且不会缩放至缓慢水平,而且由于某种原因,地图缩小得比需要的还要多。我希望地图只在需要时缩小,以便标记可以看到。



有什么建议吗?谢谢!

  clearOverlays(); 
downloadUrl(AllActivityxml.php,function(data){
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName(marker);
for(var i = 0; i< markers.length; i ++){
var name = markers [i] .getAttribute(id);
var address = markers [i] .getAttribute id);
var type = markers [i] .getAttribute(venue_type);
var point = new google.maps.LatLng(
parseFloat(markers [i] .getAttribute (lat)),
parseFloat(markers [i] .getAttribute(lng)));
var html =< b>+ name +< / b<<<< ; br />+ address;
var icon = customIcons [type] || {};
markerBounds.extend(point);
var marker = new google.maps.Marker {
map:map,
position:point,
icon:icon.icon,
shadow:icon.shadow

});

标记的Array.push(标记);
bindInfoWindow(marker,map,infoWindow,html);
map.fitBounds(markerBounds);



}
});


解决方案

缓慢平缓 - 当您执行 fitBounds()时实际上会发生这种情况。看起来像你想要的东西像 map.panTo(),它使地图上的过渡变得很慢,不像 map.setCenter(),但fitBounds()中不是这种情况。 移动 map.fitBounds(markerBounds); 移动 map.fitBounds(markerBounds); code> for循环之外


I have this code that loads XML graphic markers, and I also set it to zoom when new markers are loaded. What I don't like however, is that the zoom happens "instantly" and doesnt zoom to level slowly, and also, for some reason the map zooms out much further than it needs too. I would like the map to zoom out only as far as it needs to so that the markers are in view.

Any suggestions? Thanks!

clearOverlays();
downloadUrl("AllActivityxml.php", function(data) {
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          var name = markers[i].getAttribute("id");
          var address = markers[i].getAttribute("id");
          var type = markers[i].getAttribute("venue_type");
          var point = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("lat")),
              parseFloat(markers[i].getAttribute("lng")));
          var html = "<b>" + name + "</b> <br/>" + address;
          var icon = customIcons[type] || {};
markerBounds.extend(point);
          var marker = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon,
            shadow: icon.shadow

          });

          markersArray.push(marker);
          bindInfoWindow(marker, map, infoWindow, html);
          map.fitBounds(markerBounds);



        }
      });
解决方案

zoom happens "instantly" and doesnt zoom to level slowly -- that is how it actually happens when you do fitBounds(). Looks like you want something like the map.panTo() which makes the transition on map slowly unlike the map.setCenter(), but that is not the case in fitBounds().

map zooms out much further than it needs too -- move the map.fitBounds(markerBounds); outside the for loop

这篇关于Google地图不会“有机地缩放”当新的标记加载时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 06:41