What i am trying to do is locate user position on map every second.I know i can call a function with setInterval(function(),1000);
I am initializing map with
ionViewDidEnter() {
this.map = leaflet.map("map").fitWorld();
this.loadmap();
}
The problem is that I can't reach map from locate function.
function locate(){
var marker;
this.map.locate({
setView: true,
maxZoom: 120
}).on("locationfound", e => {
if (!marker) {
marker = new L.marker(e.latlng).addTo(this.map);
} else {
marker.setLatLng(e.latlng);
}
}).on("locationerror", error => {
if (marker) {
map.removeLayer(marker);
marker = undefined;
}
});
}
If i delete function locate(); this.map.locate works but because i want to locate user everysecond to track their location i need to call .locate everysecond so i tried to put it in function an call that function with setinterval every second but its not working.Is there any way to locate user without puting .locate inside a function and calling it?