我需要检查新创建的 OverlayItem 的数据是否已经存在于地图上已显示的 OverlayItems 列表中。我编写了一个代码来检查 OverlayItem 的数据是否已经存在,但我遇到了错误。如何从 Overlay 中提取 OverlayItem?
我当前的代码是这样的:
//where mapOverlays = mapView.getOverlays() and overlayItem is the newly created overlayItem
public boolean isExisting(List<Overlays> mapOverlays, OverlayItem overlayItem)
{
ItemizedOverlay overlay;
OverlayItem itemToCompare;
for(int i = 0; i < mapOverlays.size(); i++)
{
overlay = (ItemizedOverlay)mapOverlays; //I am getting an error here: java.util.Collections$SynchronizedRandomAccessList (from e.getMessage()). The stack trace does not contain any specific exception but only the trace of the error pointing to this line.
existingOverlayItem = overlay.getItem(i);
if(itemToCompare.getPoint().equals(overlayItem.getPoint())
&& itemToCompare.getSnippet().equals(overlayItem.getSnippet())
&& itemToCompare.getTitle().equals(overlayItem.getTitle()))
return true; //if all data are the same
}
return false;
}