簡體   English   中英

Google Map API自定義標記圖片

[英]Google Map API Custom Marker Image

我正在尋找幫助以獲取自定義標記。 該代碼當前已損壞。 這是我的劇本。 當我在for循環中放置圖標時,它會中斷。 當我刪除它時,一切正常。

var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 3,
  center: new google.maps.LatLng(35.239313, -41.073296),
  mapTypeId: google.maps.MapTypeId.HYBRID
});
map.setOptions({ minZoom: 3, maxZoom: 15 });
var infowindow = new google.maps.InfoWindow();
var image = 'images/research-pin.png';
var marker, i;

在此循環中,當我在“ for”循環中添加“ icon”時,它不會顯示。 我需要使用相同的自定義圖像顯示多個標記。

for (i = 0; i < locations.length; i++) {  
  marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map,
    html: locations[0]
    icon: image
  });
  google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
      infowindow.setContent(locations[i][0]);
      infowindow.open(map, marker);
    }
  })(marker, i));
}

您缺少逗號。 這個:

marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map,
    html: locations[0]  //<----- missing comma
    icon: image
});

應該:

marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map,
    html: locations[0],  // <---- added comma
    icon: image
});

您應該遇到語法錯誤。

暫無
暫無

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

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