我遇到了从MAP中删除Overlay PINS的问题。
在这里我有一些过滤器:“Active”,Coal,Stone等......当我点击“Active”按钮时,它会调用mineral_status(“Active”)函数并填充mapview。如果我在地图上应用了两到三个过滤器。它正在填充,但当我想从地图中删除“活动”引脚时,我无法删除。
任何人都可以指导我,我是Android的首发。
提前致谢。
public void mineral_status(String mineral_status){
Log.e("minetype", "" + mineral_status);
mapView = (MapView) findViewById(R.id.mapview);
mapOverlays = mapView.getOverlays();
try {
dbAdapter.open();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Cursor status = dbAdapter.minearls(mineral_status);
if (status == null) {
Toast.makeText(MapActivity1.this, "No items to display",
Toast.LENGTH_LONG).show();
} else {
int n = status.getCount();
Log.d("Status cursor", "" + status);
Log.d("n", "" + n);
if (status != null) {
if (status.moveToFirst()) {
do {
int latitude = (int) (status.getFloat(status
.getColumnIndex("LATITUDE")) * 1E6);
int longitude = (int) (status.getFloat(status
.getColumnIndex("LONGITUDE")) * 1E6);
String name = status.getString(status
.getColumnIndex("CURRENT_MINE_NAME"));
if (mineral_status == "Coal") {
point = new GeoPoint(latitude, longitude);
overlayitem = new OverlayItem(point, name,
"Coal Mineral");
drawable = this.getResources().getDrawable(
R.drawable.green);
}
if (mineral_status == "SandAndGravel") {
point = new GeoPoint(latitude, longitude);
overlayitem = new OverlayItem(point, name,
"Sand and Gravel Mineral");
drawable = this.getResources().getDrawable(
R.drawable.silver);
}
if (mineral_status == "Stone") {
point = new GeoPoint(latitude, longitude);
overlayitem = new OverlayItem(point, name,
"Stone Mineral");
drawable = this.getResources().getDrawable(
R.drawable.black);
}
if (mineral_status == "Nonmetal") {
point = new GeoPoint(latitude, longitude);
overlayitem = new OverlayItem(point, name,
"Non Metal Mineral");
drawable = this.getResources().getDrawable(
R.drawable.green);
}
if (mineral_status == "Metal") {
point = new GeoPoint(latitude, longitude);
overlayitem = new OverlayItem(point, name,
"Metal Minerals");
drawable = this.getResources().getDrawable(
R.drawable.green);
}
CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(
drawable, this);
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
} while (status.moveToNext());
MapController mapController = mapView.getController();
mapController.animateTo(point);
mapController.setZoom(5);
}
}
status.close();
dbAdapter.close();
}
}
另一堂课:
public class CustomItemizedOverlay扩展了ItemizedOverlay {
private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
private Context context;
public CustomItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public CustomItemizedOverlay(Drawable defaultMarker, Context context) {
this(defaultMarker);
this.context = context;
}
@Override
protected OverlayItem createItem(int i) {
return mapOverlays.get(i);
}
@Override
public int size() {
return mapOverlays.size();
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mapOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
dialog.show();
return true;
}
public void addOverlay(OverlayItem overlay) {
mapOverlays.add(overlay);
this.populate();
}
public void removeOverlay(OverlayItem overlay){
mapOverlays.remove(overlay);
this.populate();
}
// Removes overlay item i
public void removeItem(String name){
mapOverlays.remove(name);
populate();
//Log.e("overlay",""+myOverlays.remove(i));
}