nativescript-google-maps-sdk icon indicating copy to clipboard operation
nativescript-google-maps-sdk copied to clipboard

marker.android.remove is not a function

Open topclaudy opened this issue 6 years ago • 14 comments

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

topclaudy avatar Feb 12 '19 22:02 topclaudy

Is there a reason you can't use the MapView.removeMarker() method or MapView.removeAllMarkers()? Those will remove markers from the map.

tomjnsn avatar Mar 05 '19 21:03 tomjnsn

@tomjnsn Please read my comments

topclaudy avatar Mar 05 '19 21:03 topclaudy

Sorry @topclaudy I assumed you were looking for a solution and not reporting an issue with the library.

tomjnsn avatar Mar 05 '19 22:03 tomjnsn

@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.

tylerablake avatar Mar 22 '19 14:03 tylerablake

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)

dapriett avatar Mar 22 '19 14:03 dapriett

Yes, that's how I'm adding them. It's adding the marker fine, removing markers doesn't work on Android.

tylerablake avatar Mar 22 '19 17:03 tylerablake

I haven't tried moving markers so I'm not sure if it is working on iOS but not Android.

tomjnsn avatar Mar 23 '19 01:03 tomjnsn

Any fix/update on this?

topclaudy avatar Apr 09 '19 20:04 topclaudy

Experiencing the same thing - marker.android.remove is undefined

paul-muckypuddle avatar May 15 '19 17:05 paul-muckypuddle

Same, looks like we still can not remove markers on Android. Has anyone found a solution already?

MrSnoozles avatar Jan 27 '20 18:01 MrSnoozles

Anyone has a workaround for this? I tried calling "clear()", the native Android method, but no luck. MapView.gMap.clear();

dimitriospafos avatar Jun 11 '20 01:06 dimitriospafos

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 avatar Jun 14 '20 12:06 tylerablake

@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.

dimitriospafos avatar Jun 15 '20 00:06 dimitriospafos

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.

tylerablake avatar Jun 15 '20 01:06 tylerablake