我的网站上有一个谷歌地图,通过makethemap.php接收所有标记信息 它的工作正常,地图正确生成。但是,我不知道如何在考虑价格变量的情况下改变标记的可见性。
让我们说,当用户点击给定(下面)的单选按钮时,我希望价格变量低于1200的所有标记都消失。
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(-34.600, -58.400),
zoom: 13,
mapTypeId: 'roadmap',
scrollwheel: false,
});
var infoWindow = new google.maps.InfoWindow;
downloadUrl("makethemap.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var idofobject = markers[i].getAttribute("id");
var price = markers[i].getAttribute("price")
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = 'each marker has an individual infotext'
marker= new google.maps.Marker({
map: map,
position: point,
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.open(map, marker);
infoWindow.setContent(html);
});
}
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);
}
function doNothing() {}
<input type="radio" name="1200" value="male">Places above $1200<br>
在我通过php加载地图之前,我能够做到这一点。 任何帮助非常感谢。这困扰了我很长一段时间了!