Hi
I try to update the marker location on gmap from the json for every 10 seconds. but it draw marker on new location without remove the old one and also i want to show all the marker including client position, when i use bounds:true it only show all marker from json but it does not include client location. how do i do it? my code is below,
Any help will be appreciated.
function routemap() {
var v_buses = JSON.parse(window.
localStorage.getItem("buses"));//list of valid bus numbers
var v_routeno = JSON.parse(window.
localStorage.getItem("routeno"));//list of valid route numbers
var v_routes = JSON.parse(window.
localStorage.getItem("routes"));//list of valid routes
$('#map_canvas').gmap('
getCurrentPosition',function(position,status) {
//client position get value from gps
if ( status === 'OK' ) {
var clientPosition = new google.maps.LatLng(position.
coords.latitude, position.coords.longitude);
$('#map_canvas').gmap({ 'zoom':14, 'center':clientPosition});
$('#map_canvas').gmap('
addMarker',{'position': clientPosition, 'icon':"images/male-2.png"}).click(function() {
$('#map_canvas').gmap('
openInfoWindow', {'content': 'your location', draggable:true}, this)
});
}
else {
alert("position error");
}
});
setInterval(function () {
for(var i = 0; i < v_buses.length; i++) {
var id = v_buses[i];
var bno=v_routeno[i];
var route=v_routes[i];
$.getJSON('/route/'+id+'/'+
bno+'/'+route,function(data){
if(data.status == 'ok'){
$.each( data.markers, function(i, marker) {
$('#map_canvas').gmap('
refresh');
$('#map_canvas').gmap('
addMarker', {
'position': new google.maps.LatLng(marker.
latitude, marker.longitude),
'bounds': true,
'icon':"images/bus2.png" }).click(function() {
$('#map_canvas').gmap('
openInfoWindow', { 'content': 'Bus no: '+data.bno+'<br>Route: '+data.route }, this);
});
});
}