已遵循googlemapsapi教程顯示標記,現在正在尋找定期添加它們。已經看過Google Maps V3: Updating Markers Periodically但我只得到了地圖,並沒有標記顯示....我的代碼如下...谷歌地圖 - 定期更新標記
function load() {
//map object
var map = new google.maps.Map(document.getElementById("map"), {
center: {lat: 54.870902, lng: -6.300565},
zoom: 14
});
//first call to get and process initial data
downloadUrl("Map.php", processXML);
}
function processXML(data){
//method to retrieve information via ajax
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
//clear markers before adding new ones
resetMarkers(markersArray);
for(var i =0; i<markers.length; i++){
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var marker = new google.maps.Marker({
map:map,
position: point
});
//store marker object in new array
markersArray.push(marker);
marker.setMap(map);
}
//set timeout
setTimeout(function() {
downloadUrl("Map.php", processXML);
}, 1000);
}
//cleatr existing markers from map
function resetMarkers(arr){
for(var i = 0; i<arr.length; i++){
arr[i].setMap(null);
}
//reset the main marker array
arr = [];
}
檢查控制檯是否顯示了一些JavaScript錯誤 – scaisEdge
沒有答案,但希望值得一看。 https://rawgit.com/allenhwkim/angularjs-google-maps/master/testapp/marker_dynamic_ng_repeat.html。有關完整的文檔,請http://ngmap.github.io – allenhwkim