The idea is to make dynamic markers using google maps API. I want to remove the created markers first before new markers show up. I don't want to make any Arry to manage markers. because I simply want them to be removed without putting them to an array and then delete it from there.
I am calling deleteMarker
function inside the loop to do this.
I have used a global variable but I get this error:
TypeError: Mark is undefined[Learn More]
code:
var map;
var Mark;
//setInterval(function(){ alert("Hello"); }, 3000);
setInterval(ajaxCall, 9000); //300000 MS == 5 minutes
function ajaxCall() {
$.ajax({
url: '/maps/my_ajax_request/',
datatype: 'json',
type: 'GET',
success: function (data) {
for(var prop in data) {
var item = data[prop];
console.log(item.latitude,item.longitude, item.icon);
if (item.icon === "online") {
selected_status = online;
} else {
selected_status = offline;
}
deleteMarker();
this.Mark = new google.maps.Marker({
position: {lat: (parseFloat(item.latitude)), lng: (parseFloat(item.longitude))},
map: map,
icon: selected_status
});
}
},
failure: function(data1) {
alert("Got an error dude");
}
});
}
function deleteMarker() {
Mark.setMap(null);
Mark=null;
}