0
我想設置一個谷歌地圖圖標取決於一個整數。 I.E.如果變量是3,它會將圖標設置爲棕色圖像標記。我已經按照這裏找到https://developers.google.com/maps/documentation/javascript/examples/icon-simple教程這裏
How can I change the color of a Google Maps marker?谷歌地圖圖標
這是我的代碼,我的圖片都位於同一目錄中,但是當我加載頁面我得到一個錯誤說在圖標意外標識符:圖像。有什麼問題?
function getlocations(){
var data = <?php echo getjson(); ?>;
var i = 0;
var locations = new Array();
for(i; i < data.length; i++){
var dataholder = [data[i].misc, parseFloat(data[i].lat), parseFloat(data[i].lng), parseInt(data[i].status)];
locations.push(dataholder);
}
return locations;
}
function createmap() {
var locations = getlocations();
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 13,
center: new google.maps.LatLng(47.624561, -122.356445),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
var markers = new Array();
var image;
for (i = 0; i < locations.length; i++) {
if (locations[i][3] == 3) {
image = 'brown_MarkerA.png';
} else if (locations[i][3] == 4) {
image = 'brown_MarkerB.png';
} else {
image = 'brown_MarkerC.png';
}
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
icon: image
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
function AutoCenter() {
var bounds = new google.maps.LatLngBounds();
$.each(markers, function (index, marker) {
bounds.extend(marker.position);
});
map.fitBounds(bounds);
}
AutoCenter();
}
奇怪。感覺它應該工作。我們能否看到'locations'數組內容的例子? – MrUpsidown
你在'map:map'後面缺少逗號'',' – Craicerjack
修正了它。非常感謝你。花了一個小時尋找那個錯誤,現在踢自己。 – Walorn