我有一个用于移动设备的谷歌地图应用程序。我使用 jquery 移动脚本。当用户单击标记时,图标必须更改。谁没有变化是可见的。为了控制脚本,我临时构建了两个警报来检查图标是否已更改。警报显示正确的更改,但不显示地图。谁能告诉我我做错了什么?
var mobileDemo = { 'center': '52.3702157,4.8951679', 'zoom': 10 };
var marker;
$('#gps_map').live('pageinit', function() {
demo.add('gps_map', function() {
$('#map_canvas_2').gmap({center: mobileDemo.center, zoom: mobileDemo.zoom, zoomControl: true, disableDefaultUI:true, callback: function(map) {
var self = this;
var markers = new Array();
downloadUrl("map_genxml.php?projectid=1&campid=23", function(data) {
var xml = data.responseXML;
var tekst=[];
var meetid=[];
var icoon=[];
markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
tekst[i] = markers[i].getAttribute("tekst");
meetid[i] = markers[i].getAttribute("meetid");
icoon[i] = markers[i].getAttribute("icoon");
var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
if (icoon[i]=="groen") {
var icon = 'http://www.mijnmonitoring.nl/icons/green-dot.png';
} else {
var icon = 'http://www.mijnmonitoring.nl/icons/grijs-dot.png';
}
marker = new google.maps.Marker({
position: point,
icon: icon,
bounds: true
});
bindInfoWindow(marker, tekst[i], meetid[i], i);
$('#map_canvas_2').gmap('addMarker',marker).click(function() {
});
}
});
}});
}).load('gps_map');
});
function bindInfoWindow(marker, info, meetid, i) {
google.maps.event.addListener(marker, 'click', function() {
alert(marker.getIcon());
marker.setIcon('http://www.mijnmonitoring.nl/icons/red-dot.png');
alert(marker.getIcon());
document.getElementById('meetpunt').innerHTML=info;
document.getElementById('formulier').style.display='block';
});
}
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() {}
$('#gps_map').live('pageshow', function() {
demo.add('gps_map', function() { $('#map_canvas_2').gmap('refresh'); }).load('gps_map');
});