我有一系列自定义图标:
var iconBase = 'http://localhost/icons/';
var icons = {
red: {
icon: iconBase + 'red.png'
},
green: {
icon: iconBase + 'green.png'
},
info: {
icon: iconBase + 'red.png'
}
};
现在,当我在Marker中将它们称为icon: icons[red].icon,
at:
var marker = new google.maps.Marker({
position: latlng,
icon: icons[red].icon,
map: map
});
我没有在地图上找到任何标记你能告诉我我做错了什么吗?这是整个代码:
var map;
$(document).ready(function () {
var latlng = new google.maps.LatLng(49.241943, -122.889318);
var myOptions = {
zoom: 17,
center: latlng,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scaleControl: true,
panControl: true,
mapTypeControl:true,
mapTypeControlOptions: {
style:google.maps.MapTypeControlStyle.DROPDOWN_MENU,
position:google.maps.ControlPosition.TOP_CENTER
},
zoomControl: true
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
//Icon Contoling
var iconBase = 'http://localhost/icons/';
var icons = {
red: {
icon: iconBase + 'red.png'
},
green: {
icon: iconBase + 'green.png'
},
info: {
icon: iconBase + 'red.png'
}
};
var marker = new google.maps.Marker({
position: latlng,
icon: icons[red].icon,
map: map
});
});
答案 0 :(得分:1)
ReferenceError:未定义红色
尝试更改
icon: icons[red].icon
到
icon: icons['red'].icon