ionic-team / ionic-team/ionic-native-google-maps

The new marker has updated its location but old marker not remove in ionic native google map

Open
#363 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
215
Forks
119
PR merge metrics
No merged PRs in 30d

Description

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 =>

```
loadMap() {

this.map = GoogleMaps.create('map_canvas', {
controls: {
myLocationButton : true,
myLocation : true
},
camera: {
target: {
lat: this.latitude, lng: this.longitude
},
zoom: 18,
tilt: 30
},
});

this.map.addMarker({
position: { lat: this.latitude, lng: this.longitude },
draggable: true,
disableAutoPan: true,
icon: 'blue',
title: 'Avirup'
}).then((marker: Marker) => {
marker.showInfoWindow();

const subscription = this.geolocation.watchPosition().subscribe(position => {
let geoposition = (position as Geoposition);
let latitude = geoposition.coords.latitude;
let longitude = geoposition.coords.longitude;
let marker : Marker
marker = this.map.addMarkerSync({
position: { lat: latitude, lng: longitude },
draggable: true,
disableAutoPan: true,
icon: { url: './assets/image/addresspin.png' ,
size: {
width: 30 ,
height: 30
}},
title: 'Move'
})
marker.showInfoWindow();
if(marker.getPosition().lat == latitude && marker.getPosition().lng == longitude){
marker.remove()
}
})
} ```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.