ExploreMapFragment.java: fix removeMarker() to remove the correct marker (#6279)
Some checks are pending
Android CI / Run tests and generate APK (push) Waiting to run

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().
This commit is contained in:
Jason-Whitmore 2025-04-09 22:19:31 -07:00 committed by GitHub
parent 2eed441462
commit 262efe4d8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -775,7 +775,11 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
* @param nearbyBaseMarker The NearbyBaseMarker object representing the marker to be removed. * @param nearbyBaseMarker The NearbyBaseMarker object representing the marker to be removed.
*/ */
private void removeMarker(BaseMarker nearbyBaseMarker) { private void removeMarker(BaseMarker nearbyBaseMarker) {
Place place = nearbyBaseMarker.getPlace(); if (nearbyBaseMarker == null || nearbyBaseMarker.getPlace().getName() == null) {
return;
}
String target = nearbyBaseMarker.getPlace().getName();
List<Overlay> overlays = binding.mapView.getOverlays(); List<Overlay> overlays = binding.mapView.getOverlays();
ItemizedOverlayWithFocus item; ItemizedOverlayWithFocus item;
@ -784,8 +788,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
item = (ItemizedOverlayWithFocus) overlays.get(i); item = (ItemizedOverlayWithFocus) overlays.get(i);
OverlayItem overlayItem = item.getItem(0); OverlayItem overlayItem = item.getItem(0);
if (place.location.getLatitude() == overlayItem.getPoint().getLatitude() if (overlayItem.getTitle().equals(target)) {
&& place.location.getLongitude() == overlayItem.getPoint().getLongitude()) {
binding.mapView.getOverlays().remove(i); binding.mapView.getOverlays().remove(i);
binding.mapView.invalidate(); binding.mapView.invalidate();
break; break;