[英]Google Map API Custom Marker Image
I am looking for help to get a custom marker. 我正在寻找帮助以获取自定义标记。 The code is currently broken.
该代码当前已损坏。 Here is my script.
这是我的剧本。 When I put icon in the for loop, it breaks.
当我在for循环中放置图标时,它会中断。 When I remove it, everything works.
当我删除它时,一切正常。
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;
In this loop when I add "icon" to the for loop, it does not display. 在此循环中,当我在“ for”循环中添加“ icon”时,它不会显示。 I need to display multiple markers all using the same custom image.
我需要使用相同的自定义图像显示多个标记。
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));
}
You are missing a comma. 您缺少逗号。 This:
这个:
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
});
should be: 应该:
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
});
You should be getting a syntax error. 您应该遇到语法错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.