您好我正在尝试创建一个 jquery/javascript 函数,该函数将作为标题状态删除我的所有标记var markersArray
并在我的 php 脚本中请求以呈现新标记。我很难做到这一点,因为我不擅长 JS,所以这是我的代码。
我在页面上有 3 个过滤器是选择元素 这里是我的 JS 脚本
$('#lgu,#category,#type').change(function(){
google.maps.Map.prototype.clearOverlays = function() {
for (var i = 0; i < markersArray.length; i++ ) {
markersArray[i].setMap(null);
}
}
var lgu = $('#lgu').val();
var category = $('#category').val();
var type = $('#type').val();
$.get('xmlquery.php', { input: lgu, input2: category, input3: type},function(data){
downloadUrl("xmlspitter.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + name + "</b> <br/>" + address;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
});
markersArray.push(marker);
bindInfoWindow(marker, map, infoWindow, html);
}
});
});
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
});
将不胜感激任何帮助。
请注意,我是 JS 的菜鸟,这意味着我也是调试它的菜鸟,请帮忙。