google maps - JQuery - refresh a marker position (to get movement) -
i have gps based system sends mysql database coordinates.
using code:
(function() { window.onload = function() { // creating 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 json data (var = 0, length = json.locations.length; < 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 click event current marker google.maps.event.addlistener(marker, "click", function(e) { infowindow.setcontent(data.nome); infowindow.open(map, marker); }); })(marker, data); /* movemarker( map, marker ); */ } } // json data php script var json ; $.getjson("http://mywebservice/nmea_last.php").done(function(data) { json = data; createpoints(json); }); } })();
uding getjson("http://mywebservice/nmea_last.php")
sentence, last coordinates gps sends (pediodically) mysql, , marker appears correctly. question is, how dinamically refresh of marker catch movement on map?
i think need use settimeout method (or not?) not know how. help? in advance.
i suggest looking @ setinterval function, can use call function on regular intervals. information can found here.
i believe want wrap getjson call within setinterval function pull new points , refresh map. example fire getjson call every 5 seconds:
setinterval(function() { $.getjson("http://mywebservice/nmea_last.php").done(function(data) { json = data; createpoints(json); }); }, 5000);
Comments
Post a Comment