Javascript 谷歌地图API自定义标记图像
我正在寻求帮助,以获得一个自定义标记。代码当前已被破坏。这是我的剧本。当我将图标放入for循环时,它会断开。当我移除它时,一切正常Javascript 谷歌地图API自定义标记图像,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我正在寻求帮助,以获得一个自定义标记。代码当前已被破坏。这是我的剧本。当我将图标放入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.se
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));
}
(i=0;i
marker=新的google.maps.marker({
位置:新的google.maps.LatLng(位置[i][1],位置[i][2]),
地图:地图,
html:位置[0]
图标:图像
});
google.maps.event.addListener(标记,'click',(函数(标记,i){
返回函数(){
infowindow.setContent(位置[i][0]);
信息窗口。打开(地图、标记);
}
})(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({
位置:新的google.maps.LatLng(位置[i][1],位置[i][2]),
地图:地图,
html:位置[0]//
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
});