如何从Osmdroid映射中删除标记
我正在创建一个Android应用程序,需要在地图上设置标记.而且由于我的应用程序需要离线功能,因此我需要使用Osmdroid解决此问题.现在我的问题是地图上的标记,我可以使用Markers或ItemizedOverlay轻松添加它们,但是我遇到的问题是我无法从地图上删除标记.
I'm creating an Android Application where i need to set markers on the map. And since my App requires Offline function i need to use Osmdroid to solve this problem. Now my issue is the markers on the map, which i can easily add them by using Markers or the ItemizedOverlay, but the issue i'm having is that i cannot remove markers from the map.
我用来添加标记的代码是这样的:
The code i have used for adding markers is this one:
Marker marker = new Marker(mapView);
marker.setPosition(new GeoPoint(41.3746312,19.7710733));
marker.setIcon(getResources().getDrawable(R.drawable.marker));
marker.setImage(getResources().getDrawable(R.drawable.marker));
marker.setTitle("Marker");
marker.setInfoWindow(null);
marker.showInfoWindow();
mapView.getOverlays().add(marker);
mapView.invalidate();
但是我在删除它们时遇到了问题,因为删除它的唯一方法是:
but i'm encountering issues on removing them since the only way to remove it is:
mapView.getOverlays().clear();
我需要删除一个特定的标记,而不是同时删除所有标记.
And i need to remove a specific marker instead of all of them at the same time.
要删除特定标记,应使用:
For removing specific marker you should use:
mapView.getOverlays().remove(overlay);
mapView.invalidate();