2011-05-20 139 views
0

我使用谷歌地圖顯示標記與信息窗口..我顯示地址,但我想顯示名稱以及在信息窗口中點擊標記時。任何幫助將不勝感激。谷歌地圖信息窗口

function load() var map = new GMap2(document.getElementById(「map」));
map.setCenter(new GLatLng(-37.816667,144.966667),10); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl());

 var geocoder = new GClientGeocoder(); 
    GDownloadUrl("shops.xml", function(data) { 

     var xml = GXml.parse(data); 
     shop = xml.documentElement.getElementsByTagName("shop"); 
     for (var i = 0; i < shop.length; i++) { 
     var name= shop[i].getElementsByTagName("name"); 
     name = name[0].childNodes[0].nodeValue; 
     var address= shop[i].getElementsByTagName("address"); 
     address = address[0].childNodes[0].nodeValue; 
     geocoder.getLocations(address, addToMap);} 

      }); } 

功能addToMap(響應) { 地點= response.Placemark [0]; point = new GLatLng(place.Point.coordinates [1],place.Point.coordinates [0]);

function createMarker(point,address) 
    {  
    var marker = new GMarker(point);  
    GEvent.addListener(marker, "click", function() 
    {  
    map.openInfoWindowHtml(point, address);  
    });  
    return marker; 
    } 
    map.addOverlay(createMarker(point, response.name)); 

}

回答

0

使用API​​ v3和你的標誌設置中設置的標誌爲「名」的滴度然後加入點擊監聽器,你就可以參考所點擊的標記標題後 - 如果那是你想要的。

//get your point and name whatever way you plan to do it 
... 

function createMarker(point,name){ 

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

var content='Whatever info you want plus'+name; 

var infowindow = new google.maps.InfoWindow({ 
    content: content 
}); 

google.maps.event.addListener(marker, 'click', function() { 
    infowindow.open(map,marker); 
}); 
return marker; 
} 

請檢查我剛剛寫的關閉。 K

+0

你能告訴我一些代碼 – mike 2011-05-21 01:21:28