我有一個基於GPS的系統發送到MYSQL數據庫的座標。JQuery - 刷新標記位置(獲取移動)
使用此代碼:
(function() {
window.onload = function() {
// Creating a new map
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(41.65, -0.88),
zoom: 1,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
function createPoints(json){
var infoWindow = new google.maps.InfoWindow();
// Looping through the JSON data
for (var i = 0, length = json.locations.length; i < length; i++) {
var data = json.locations[i],
latLng = new google.maps.LatLng(data.lat, data.long);
var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';
var marker = new google.maps.Marker({
position: latLng,
map: map,
title: data.nome,
icon: iconBase + 'schools_maps.png'
});
(function(marker, data) {
// Attaching a click event to the current marker
google.maps.event.addListener(marker, "click", function(e) {
infoWindow.setContent(data.nome);
infoWindow.open(map, marker);
});
})(marker, data);
/* moveMarker(map, marker); */
}
}
// Get the JSON data from PHP script
var json ;
$.getJSON("http://mywebservice/nmea_last.php").done(function(data) {
json = data;
createPoints(json);
});
}
})();
UDING getJSON("http://mywebservice/nmea_last.php")
一句,我得到的,全球定位系統發送(pediodically)到MySQL的最後一個座標,並標記正確顯示。我的問題是,我怎樣才能在地圖上進行動態刷新?
我想我需要使用setTimeout方法(或不?),但我不知道如何。任何幫助? 在此先感謝。
非常感謝!它似乎工作正常...只有一件事:我有多冷,刪除previouse標記? (實際上它堅持在地圖上) – doxsi 2013-05-13 17:07:31
我自己無法想到具體的解決方案,但這可能會導致您朝着正確的方向發展:http://stackoverflow.com/questions/1544739/google-maps-api-v3-如何去除的,所有標誌物 – theaccordance 2013-05-13 18:44:26