2010-08-03 56 views
0

這是我到目前爲止。使用Google Maps JavaScript API v3,如何在點擊時生成默認信息框?

function init_map() { 
    var places = [ 
     { name: "Place 1", coords: new google.maps.LatLng(30.728752, -73.995525)}, 
     { name: "Place 2", coords: new google.maps.LatLng(30.733673, -73.990028)}, 
     { name: "Place 3", coords: new google.maps.LatLng(40.725778, -73.992249)} 
    ] 

    var myOptions = { 
     zoom: 14, 
     center: places[0].coords, 
     mapTypeId: google.maps.MapTypeId.ROADMAP, 
    } 

    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

    for (var x=0; x < places.length; x++){ 
     var place = places[x]; 
     var marker = new google.maps.Marker({ 
      position: place.coords, 
      title: place.name, 
      icon: icon, 
      clickable: true, 
      infowindow: new google.maps.InfoWindow({content:"hello world"}) 
     }); 
     marker.setMap(map); 

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

我想有默認的信息窗口的地址搜索時,谷歌地圖出現,而不是我自己的自定義窗口,你會看到。這怎麼可能?

+0

從看你的代碼,無論如何它是這樣做的。只要確保你沒有任何重疊的CSS樣式!因爲這可以搞砸你的工具提示。 – 2010-08-04 13:57:44

+0

它實際上沒有。如果你創建一個InfoWindow,它希望你在其中放入內容。我希望它有它的默認谷歌內容。 – blackrobot 2010-08-04 14:28:01

回答

0

您的默認Google內容是什麼意思?

此外,創建1個infowindow對象然後在您的標記中共享它可能會更好。

相關問題