2017-06-20 68 views
-1

下面是我的網站上的jQuery代碼。 ADS-B Recviver正在上傳現場.JSON文件,提供飛機的經緯度信息。我已將它們製作成標記,但它們只會在刷新頁面時更新。我試過設定的時間間隔,並做了大量的研究,但沒有太多。 任何想法,我可以做什麼?也許我沒有把Set Interval放在正確的地方。移動/更新基於JSON的標記

function initialize() { 

var mapOptions = { 
center: new google.maps.LatLng(-36.363, 175.044), 
zoom: 5, 
mapTypeId: google.maps.MapTypeId.ROADMAP 
}; 

var infoWindow = new google.maps.InfoWindow(); 
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 



$.getJSON('https://crossorigin.me/http://radar1.ddns.net:3080/data/aircraft.json', function(data){ 
      $.each(data.aircraft, function(i, value) { 


      var myLatlng = new google.maps.LatLng(value.lat, value.lon, value.flight, value.altitude); 
      var marker = new google.maps.Marker({ 
      position: myLatlng, 
      icon: 'airplane.jpg', 
      map: map, 
      title: "Callsign Altitude "+value.flight+value.altitude 

      }); 

    var marker = new google.maps.Marker({ 
position: new google.maps.LatLng(-37.008625, 174.785047), 
icon: 'airport.png', 
map: map, 
});   



     }); 
}); 


} 

回答

0

嘿Kieran嘗試下面的代碼,它會刷新每20秒後的地圖。

<script type="text/javascript"> 
var timerID = null; 
var map; 
var timerRunning = false; 
var delay = 20000; // refresh every 20 seconds 
var zoomToExtents = 0; 
var openedInfoWindow = null; 
// Initialize Timer 
function initializeTimer() { 

    initialize(); 
    StopTheClock(); 
    StartTheTimer(); 
} 
function StopTheClock() { 
    if (timerRunning) 
     clearTimeout(timerID) 
    timerRunning = false; 
} 
function StartTracking() { 
    StartTheTimer(); 
} 
function StartTheTimer() { 
    // alert('hi'); 
    readData(); 
    timerRunning = true; 
    timerID = self.setTimeout("StartTracking()", delay) 
} 


google.maps.event.addDomListener(window, 'load', initializeTimer); 
function initialize() { 

    var mapOptions = { 
     center: new google.maps.LatLng(-36.363, 175.044), 
     zoom: 5, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 

    var infoWindow = new google.maps.InfoWindow(); 
    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 
} 
    function readData() { 

     $.getJSON('https://crossorigin.me/http://radar1.ddns.net:3080/data/aircraft.json', function (data) { 
      $.each(data.aircraft, function (i, value) { 


       var myLatlng = new google.maps.LatLng(value.lat, value.lon, value.flight, value.altitude); 
       var Latlngs = new google.maps.LatLng(-37.008625, 174.785047); 
       map.setCenter(Latlngs); 
       var marker = new google.maps.Marker({ 
        position: myLatlng, 
        icon: 'airplane.jpg', 
        map: map, 
        title: "Callsign Altitude " + value.flight + value.altitude 

       }); 

       var marker = new google.maps.Marker({ 
        position: new google.maps.LatLng(-37.008625, 174.785047), 
        icon: 'airplane.jpg', 
        map: map, 
       }); 



      }); 
     }); 

    } 

+0

磨憨您好,感謝它的作品!只是一個小問題,舊的職位仍然顯示出任何方式來消除這一點,只是顯示ifs歷史背後的線?或只是一個圖標。 –