Open GhoshWorld opened 2 years ago
This work only change some code. We can change addMarkerSync
to addMarker
event. ::
watchPosition() {
this.geolocation.watchPosition().subscribe(position => {
let geoposition = (position as Geoposition);
let latitude = geoposition.coords.latitude;
let longitude = geoposition.coords.longitude;
this.map.addMarker({
position: { lat: latitude, lng: longitude },
draggable: true,
disableAutoPan: true,
icon: {
url: './assets/image/addresspin.png',
size: {
width: 30,
height: 30
}
},
title: 'Avirup Move'
}).then((marker: Marker) => {
if (marker) {
setTimeout(() => {
marker.remove()
}, 1000)
} else {
console.log("marker", marker)
marker.showInfoWindow();
marker.on(GoogleMapsEvent.MARKER_CLICK).subscribe(() => {
console.log("markeron")
});
marker.trigger(GoogleMapsEvent.MARKER_CLICK);
}
});
})
}
The marker is updating to new position and set a new marker but problem with old position marker not remove. marker.remove() not work under this if condition. How I remove old marker? any solution please. here is my code =>