簡體   English   中英

Google Maps v3 Infowindow無法正常工作

[英]Google maps v3 Infowindow is not working

我已經按照JS代碼制作Google地圖標記,並且我也嘗試在每個標記上制作信息窗口,但通過我的代碼,信息窗口未打開,這是我的代碼

for(i=0; i<GPS.length; i++)
    {

          var image = 'ico/no.png';
          var infowindow = new google.maps.InfoWindow();
          var ContentString = GPS[i].TITLE
          markers[i] = new google.maps.Marker(
          { 
           position: GPS[i].GPS,
           map: map,
           draggable:true,
           icon:image,
           title:GPS[i].TITLE
           });                       

            google.maps.event.addListener(markers[i], 'click', function() {
            infowindow.setContent(ContentString);
            infowindow.open(map,markers[i]);
            });


    }    

如果我沒記錯的話,看來您這里有關閉問題。

查看鏈接以查看如何解決Google地圖中的關閉問題

來自Google的以下簡單代碼將在地圖上顯示標記

var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var myOptions = {
  zoom: 4,
  center: myLatlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
}

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

var contentString = '<div id="content">'+
    '<div id="siteNotice">'+
    '</div>'+
    '<h2 id="firstHeading" class="firstHeading">Uluru</h2>'+
    '<div id="bodyContent">'+
    '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
    'sandstone rock formation in the southern part of the '+
    'Northern Territory, central Australia. It lies 335 km (208 mi) '+
    'south west of the nearest large town, Alice Springs; 450 km '+
    '(280 mi) by road. Kata Tjuta and Uluru are the two major '+
    'features of the Uluru - Kata Tjuta National Park. Uluru is '+
    'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
    'Aboriginal people of the area. It has many springs, waterholes, '+
    'rock caves and ancient paintings. Uluru is listed as a World '+
    'Heritage Site.</p>'+
    '<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
    'http://en.wikipedia.org/w/index.php?title=Uluru</a> (last visited June 22, 2009).</p>'+
    '</div>'+
    '</div>';

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

var marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title:"Uluru (Ayers Rock)"
});

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

您必須確保先實例化地圖對象,然后是contentString,然后是標記,然后是infowindow對象,最后添加一個點擊偵聽器。 代碼是按順序執行的,因此在邏輯上進行檢查時必須有意義。 希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM