I have one function called loadmap(){} where im creating map.Im loading this function with
ionViewDidEnter() {
this.loadmap();
}
Inside loadmap i have
this.map = leaflet.map("map").fitWorld();
thats how i initialize map
This is how i remove map when user changes tab.
ionViewDidLeave(){
this.map.remove();
}
This is my .locate function:
var usermarker;
this.map.locate({
setView: true,
maxZoom: 120,
watch:true,
enableHighAccuracy:true
}).on("locationfound", e => {
if (!usermarker) {
usermarker = new L.marker(e.latlng).addTo(this.map);
} else {
usermarker.setLatLng(e.latlng);
}
}).on("locationerror", error => {
if (usermarker) {
this.map.removeLayer(usermarker);
usermarker = undefined;
}
});
The problem is in first time .locate function works.but if i change tab and go back to map tab .locate function doesnt work.if i remove watch option it works.
Thanks