I have a GPS based system that sends to a MYSQL database the coordinates.
Using this code:
(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")
sentence, I get the last coordinates that gps sends (pediodically) to the mysql, and marker appears correctly. My question is, how could I get the dinamically refresh of the marker to catch the movement on map?
I think I need to use setTimeout method (or not?) but I do not know how. Any help? Thanks in advance.