2012-09-13 87 views
0

雖然我在Gmapv2..version得到這個工作三是證明是有點麻煩。添加XML屬性GMap3 infoBubbles

我想其他的屬性添加到XML文件中的infobubble,但無論我嘗試添加它們,它打破了上點擊標記?

<script type="text/javascript"> 
    var infowindow; 
    var map; 
    function initialize() { 

     var myLatlng = new google.maps.LatLng(54.046575, -2.8007399); 
     var myOptions = { 
      zoom: 13, 
      center: myLatlng, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     } 
     map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
     downloadUrl("http://www.xxxxxx.com/xxxxx.com/server/venue_output.php",   function(data) { 
      var markers = data.documentElement.getElementsByTagName("marker"); 
      for (var i = 0; i < markers.length; i++) { 
      var latlng = new   google.maps.LatLng(parseFloat(markers[i].getAttribute("latitude")), 
           parseFloat(markers[i].getAttribute("longitude"))); 
           var event_name =   markers[i].getAttribute("event_title"); 
     var event_start = markers[i].getAttribute("event_start"); 
     var event_link = markers[i].getAttribute("event_link");  
      var marker = createMarker(markers[i].getAttribute("event_name"),latlng); 
      } 
     }); 
     } 

     function createMarker(name, latlng) { 
     var marker = new google.maps.Marker({position: latlng, map: map, bounce:true, icon : new google.maps.MarkerImage('http://www.gigizmo.com/gigizmo.com/app/images/marker.png')}); 
     google.maps.event.addListener(marker, "click", function() { 
      if (infowindow) infowindow.close(); 
      infowindow = new google.maps.InfoWindow({content: "<b>" + name + "</b>" }); 
      infowindow.open(map, marker); 
     }); 
     return marker; 
     } 

    </script> 

如何將我的javascript值(如event_link)添加到此標記窗口?

infowindow = new google.maps.InfoWindow({content: "<b>" + name + "</b>" }); 

回答

0

你可以試試這個代碼片斷,在提供:this example

function createMarker(..){ 

     eval(" infowindow"+time+" = new google.maps.InfoWindow({ content: pt.latLng.toString() });"); 
     eval(" marker"+time+" = new google.maps.Marker({ position: pt.latLng, map: map });"); 
     eval(" google.maps.event.addListener(marker"+time+", \"click\", function() { infowindow"+time+".open(map, marker"+time+"); });"); 
     time++; 
//rest of your code 
} 

而且也,我以前的經驗來說: 要確保你的XML文件不包括換行符。 特別是作爲價值,你設置爲「name」的變量。