nativescript-google-maps-sdk
nativescript-google-maps-sdk copied to clipboard
marker.android.remove is not a function
When trying to remove a marker from the map on Android, I get the error: marker.android.remove is not a function
It works fine on iOS. I notice that the iOS code just calls marker.ios.map = null
in the removeMarker function. But the Android code invokes the method remove on the marker, marker.android.remove()
marker.android is an instance of com.google.android.gms.maps.model.MarkerOptions which doesn't expose a remove() method. remove is a method of com.google.android.gms.maps.model.Marker
Is there a reason you can't use the MapView.removeMarker() method or MapView.removeAllMarkers()? Those will remove markers from the map.
@tomjnsn Please read my comments
Sorry @topclaudy I assumed you were looking for a solution and not reporting an issue with the library.
@tomjnsn Do you have a work around for this? I just want to update the marker with a new position, it works on iOS but Android isn't.
How are you adding your markers - using this.mapView.addMarker(marker)
?
That's where the MarkerOptions get converted to Marker for android:
https://github.com/dapriett/nativescript-google-maps-sdk/blob/master/src/map-view.android.ts#L387 https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.html#addMarker(com.google.android.gms.maps.model.MarkerOptions)
Yes, that's how I'm adding them. It's adding the marker fine, removing markers doesn't work on Android.
I haven't tried moving markers so I'm not sure if it is working on iOS but not Android.
Any fix/update on this?
Experiencing the same thing - marker.android.remove is undefined
Same, looks like we still can not remove markers on Android. Has anyone found a solution already?
Anyone has a workaround for this? I tried calling "clear()", the native Android method, but no luck. MapView.gMap.clear();
Hi @dimitriospafos,
I was able to successfully remove a marker using this.mapView.removeMarker(stLouisMarker);
inside of my component.ts file.
Make sure the marker you are passing into that method is the correct one and isn't empty.
@tylerablake looks like it works. I was having a different issue when I was trying to re-add a marker after removing all of the markers from the map and I thought it could be failing because of the issue mentioned above. Something like:
var marker = this.mapView.findMarker(m => m.infoWindowTemplate === "myInfoTemplateName");
this.mapView.removeAllMarkers();
this.mapView.addMarker(marker);
The above fails on "addMarker" in Android but works for IOS. I just created a new marker instead of reusing the same one and it seems like it works now.
Thanks for taking the time to look into it.
Ok, that might be a quirk of Android V8 vs iOS JavaScript Core.
I bet V8 sets marker
as a reference to the marker on the map (which is deleted when you run removeAllMarkers()
) where JavaScript Core sets as a value.