Hi all,
i'm currently workin on a project and i need to show on a maps the live position of my car.
i have an arduino wich send every 5sec to my DB the position
The problem is that i can't figure out how to refresh my polylines every 5second without reloading the page!
any help will be realy apreciate.
thanks
riccardo
<?php
$result = mysql_query("SELECT `lat`, `lng` FROM `valori' ");
while($r = mysql_fetch_assoc($result, MYSQL_NUM)) {
$rows[] = $r;
}
?>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: {lat: 51.5202863763, lng: -0.183619436312},
mapTypeId: google.maps.MapTypeId.SATELLITE
});
$(window).load(function(){
update()
setInterval(function(){
update()
}, 5000)
})
function update(){
var polylinePlanCoordinates = [];
var polyline_data = <?php echo json_encode( $rows ); ?>;
for (var i=0;i< polyline_data.length;i++ ){
polylinePlanCoordinates.push(new google.maps.LatLng(polyline_data[i][0], polyline_data[i][1]));
}
var path= new google.maps.Polyline({
path: polylinePlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
}
path.setMap(map);
}
</script> <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyABLjW3bN2UJK6srnKF05jwGTyFUPzxWuY&callback=initMap"></script>