0

When i click on marker always show the same data... why?

code:

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

}

j0k
  • 22,600
  • 28
  • 79
  • 90
Andrew
  • 2,128
  • 3
  • 24
  • 42
  • How does infowindow associate with dialog? I see you create an InfoWindow but you never do anything with it. And then in the event listener where I'd expect to see InfoWindow code I see dialog. What's the relationship? – Khepri Jun 13 '11 at 21:40
  • No, i dont want to see infowindow. i want to see jquery window (dialog) insted of infowindow but in jquery dialog i see the same data. Please see on http://kuponik.adriamart.com/davidimo.html – Andrew Jun 13 '11 at 21:56
  • There is no marker on map from [link you posted](http://kuponik.adriamart.com/davidimo.html) in last comment. – Sparky Jun 13 '11 at 22:24
  • please look again becouse is marker on serbia, belgrade and i dont center lat,lng on that... just zoom out map. – Andrew Jun 13 '11 at 22:37
  • @adria: Western US and Eastern Europe; you can't get any further apart than that! LOL... ok I see it now. – Sparky Jun 13 '11 at 22:41

2 Answers2

1

Try this:

1st change

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

to

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

2nd add the following function:

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

Hope it helps

K

kwicher
  • 2,092
  • 1
  • 19
  • 28
0

Change these lines...

var marker = new google.maps.Marker

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

to these...

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

google.maps.event.addListener(marker[i], 'click', function() 
Sparky
  • 98,165
  • 25
  • 199
  • 285