0

マーカーをクリックすると、常に同じデータが表示されます...なぜですか?

コード:

function load() 
{
  var dialog = $('<div>').dialog({autoOpen:false});
  var map = new google.maps.Map(document.getElementById("map"), 
  {
        center: new google.maps.LatLng(47.6145, -122.3418),
        zoom: 13,
        mapTypeId: 'roadmap'
  });
  var infoWindow = new google.maps.InfoWindow;


  // Change this depending on the name of your PHP file
  downloadUrl("phpsqlajax_genxml.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("name");
      var address = markers[i].getAttribute("address");
      var type = markers[i].getAttribute("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] || {};
      var marker = new google.maps.Marker
                   ({
                       map: map,
                       position: point,
                       icon: icon.icon,
                       shadow: icon.shadow
                   });

     google.maps.event.addListener(marker, 'click', function() 
     {
         dialog.html(html).dialog('open');
     });
    }
 });

}

4

2 に答える 2

1

これを試して:

1 回目の変更

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

google.maps.event.addListener(marker, 'click', dial(html));

2番目に次の関数を追加します。

 function dial(html){
 return function(){
 dialog = $('<div>').dialog({autoOpen:false});
 dialog.html(html).dialog('open');
 }
 }

それが役に立てば幸い

K

于 2011-06-13T23:33:36.923 に答える
0

これらの行を変更...

var marker = new google.maps.Marker

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

これらに...

var marker;
marker[i] = new google.maps.Marker

google.maps.event.addListener(marker[i], 'click', function() 
于 2011-06-13T22:50:46.910 に答える