From 262efe4d8c1b0a5bdb6d36d68cb9be0581dd4fd1 Mon Sep 17 00:00:00 2001 From: Jason-Whitmore Date: Wed, 9 Apr 2025 22:19:31 -0700 Subject: [PATCH] ExploreMapFragment.java: fix removeMarker() to remove the correct marker (#6279) Before this change, the removeMarker() method would determine the correct overlay to remove by comparing an overlay's Place coordinates with the target BaseMarker's Place coordinates. If two different markers had the same Place coordinates, the incorrect marker would be removed, leading to more than one green label appearing on the screen. After this change, the removeMarker() method now compares an overlay's title with the BaseMarker's Place name. removeMarker() will work properly as long as all BaseMarker's Place names are unique. Also, null checks were added to removeMarker(). --- .../free/nrw/commons/explore/map/ExploreMapFragment.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java index f5657dd1b..60758ac20 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java @@ -775,7 +775,11 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment * @param nearbyBaseMarker The NearbyBaseMarker object representing the marker to be removed. */ private void removeMarker(BaseMarker nearbyBaseMarker) { - Place place = nearbyBaseMarker.getPlace(); + if (nearbyBaseMarker == null || nearbyBaseMarker.getPlace().getName() == null) { + return; + } + + String target = nearbyBaseMarker.getPlace().getName(); List overlays = binding.mapView.getOverlays(); ItemizedOverlayWithFocus item; @@ -784,8 +788,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment item = (ItemizedOverlayWithFocus) overlays.get(i); OverlayItem overlayItem = item.getItem(0); - if (place.location.getLatitude() == overlayItem.getPoint().getLatitude() - && place.location.getLongitude() == overlayItem.getPoint().getLongitude()) { + if (overlayItem.getTitle().equals(target)) { binding.mapView.getOverlays().remove(i); binding.mapView.invalidate(); break;