-1
我想在顯示XML表格中的數據的Google地圖上顯示自己的自定義標記。該地圖功能正常,並顯示默認標記,但我無法解決如何更改標記以對應於我的表中的數據類型。加載與XML表中的數據相關的自定義地圖圖標 - Google Maps API v3
我一直在關注的Using PHP/MySQL with Google Maps教程,並試圖整合它們的代碼自定義標記圖標進入我的,但我一直沒能得到它的工作。在這裏還有幾個其他問題可以解決這個問題,但我還沒有能夠將答案應用到我的代碼中。
我有以下代碼第一:
var map;
var markers = [];
var infoWindow;
var locationSelect;
var customIcons = {
CP: {icon: 'icons/country_park.png'},
LNR: {icon: 'icons/lnr.png'},
PG: {icon: 'icons/parks_gardens.png'},
SAC: {icon: 'icons/sac.png'},
VG: {icon: 'icons/village_green.png'},
WALK: {icon: 'icons/walk.png'},
MG: {icon: 'icons/m_green.png'},
MBC: {icon: 'icons/mbc.png'},
WT: {icon: 'icons/wt.png'},
KWT: {icon: 'icons/kwt.png'}
};
那麼這是加載從XML的位置的部分:
var searchUrl = 'TESTxml_output.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
downloadUrl(searchUrl, function(data) {
var xml = parseXml(data);
var markerNodes = xml.documentElement.getElementsByTagName("marker");
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < markerNodes.length; i++) {
var name = markerNodes[i].getAttribute("name");
var agency = markerNodes[i].getAttribute("agency");
var type = markerNodes[i].getAttribute("type");
var distance = parseFloat(markerNodes[i].getAttribute("distance"));
var latlng = new google.maps.LatLng(
parseFloat(markerNodes[i].getAttribute("lat")),
parseFloat(markerNodes[i].getAttribute("lng"))
);
createOption(name, distance, i);
createMarker(latlng, name, agency);
bounds.extend(latlng);
}
map.fitBounds(bounds);
locationSelect.style.visibility = "invisible";
locationSelect.onchange = function() {
var markerNum = locationSelect.options[locationSelect.selectedIndex].value;
google.maps.event.trigger(markers[markerNum], 'click');
};
});
}
function createMarker(latlng, name, agency, type) {
var html = "<b>" + name + "</b> <br/>" + agency;
var icon = customIcons[type];
var marker = new google.maps.Marker({
map: map,
position: latlng,
icon: icon
});
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
markers.push(marker);
}
我要去哪裏錯了?