1

Google マップ v3 コードで問題が発生しています。それはポイントを中心にし続け、ズームしたり、実際に地図をいじったりすることはまったくできません。マップ上のプロット ポイントをクリックしても、マップの中心にすばやく調整されます。したがって、基本的には、マップ上のプロット ポイントをズームしたり使用したりできます。事前に助けてくれてありがとう。

サイト: 問題のある Web サイト

コード:

$(document).ready(function(e) {
   initialize(); 
});

var map = null;
var markersArray = [];
var markers = [];
var openedInfoWindow ="";
var geocoder = new google.maps.Geocoder();

 function initialize() {

    var mapOptions = {
      center: new google.maps.LatLng(-34.397, 150.644),
      zoom: 8,
      zoomControl: true,
      zoomControlOptions: {
        style: google.maps.ZoomControlStyle.SMALL
      },
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("mapInfoManual"),
        mapOptions);


    addMarker();      
  }





 function addMarker() {


    var bounds = new google.maps.LatLngBounds();
    for(i=0; i<markersArray.length; i++)
    {
        CodeAddress(markersArray[i]['address']);
    }
    setInterval(function()
    {

      for(i=0; i<markers.length; i++)
      {
          var point = new google.maps.LatLng(markers[i]['lat'], markers[i]      ['lng']);

          var marker = new google.maps.Marker({
              position: point,
              map: map
          });
          bounds.extend(point);

          openInfoWindow(marker,markersArray[i]['address'])         
      }
      map.fitBounds(bounds);

      },1000);

}


// Address To Marker
function CodeAddress(address)
{

geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
    lat = results[0].geometry.location.lat();
    lng = results[0].geometry.location.lng();
    markers.push({
                    'lat':lat,
                    'lng':lng,
                    'address':address
                });

} 

});   
}


//Info Window
function openInfoWindow(marker,content)
{

var infowindow = new google.maps.InfoWindow({
    content: '<div><p style=" color: #000000; font-size: 11px;">'+content+'</p>          </div>'
});



google.maps.event.addListener(marker, 'click', function() {

    if(openedInfoWindow !="")
    {
        openedInfoWindow.close()
    }


    infowindow.open(map,marker);
    openedInfoWindow = infowindow;
});
}
4

1 に答える 1

1

問題は次のとおりです。

setInterval(function()
{
  ...
  map.fitBounds(bounds);

},1000);

毎秒新しいマーカーを追加し、マップがその境界に収まるように指示します。これにより、ズーム レベルとビューポートがリセットされます。おそらく、setTimeout代わりに使用するつもりでしたか?

于 2013-03-03T13:01:14.607 に答える