我有一个从停靠列表创建的动态地图。我需要知道如何根据类别更改颜色或标记,如果可能,在标记中显示标记号:
这是我的代码:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
function initialize() {
/// Add all the markers here
var locations = [
['2',52.580326680821,-1.4575993856011, 1],
['1',52.677675034366,-1.6838465453651, 2],
['1',52.377675034366,-1.4538465453651, 3]
];
var map = new google.maps.Map(document.getElementById('MAP'), {
zoom: 10,
center: new google.maps.LatLng(52.677675034366,-1.6838465453651),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
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
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
我需要做类似
的事情var locations = [
['Title1','Category1',52.580326680821,-1.4575993856011, 1],
['Title2','Category2',52.677675034366,-1.6838465453651, 2],
['Title3','Category1',52.377675034366,-1.4538465453651, 3]
];
然后:
if(Category = Category1) {
blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
}
if(Category = Category2) {
blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png";
}
但我不知道如何实现这个以及将它放在我的代码中的位置。
非常感谢任何帮助。另外作为奖励,我需要在标记中显示制造商编号。
提前致谢
答案 0 :(得分:0)
marker.setIcon('newImage.png')
您可以将其与图片