mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
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
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:
parent
2eed441462
commit
262efe4d8c
1 changed files with 6 additions and 3 deletions
|
|
@ -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<Overlay> 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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue