我按照你告诉我的方式做了。我会在oncreate()里面撒谎,如果放了一些东西,除了来自
mapOverlays = mapView.getOverlays();
??
另外,在我的mainactivity类的开头,我声明所有的变量,我应该放什么?我有:
List<Overlay> mapOverlays;
HelloItemizedOverlay itemizedoverlay0;
HelloItemizedOverlay itemizedoverlay1;
HelloItemizedOverlay itemizedoverlay2;
HelloItemizedOverlay itemizedoverlay3;
HelloItemizedOverlay itemizedoverlay4;
HelloItemizedOverlay itemizedoverlay5;
GeoPoint point;
Drawable drawable0;
Drawable drawable1;
Drawable drawable2;
Drawable drawable3;
Drawable drawable4;
Drawable drawable5;
OverlayItem overlayItem5;
OverlayItem overlayItem0;
OverlayItem overlayItem1;
OverlayItem overlayItem2;
OverlayItem overlayItem3;
OverlayItem overlayItem4;`
对所有标记类别使用相同的geopoint变量(点)是否有问题? 为了将叠加项添加到我所做的每个类别:
try {
Drawable drawable0 = this.getResources().getDrawable(R.drawable.marker_default);
HelloItemizedOverlay itemizedoverlay0 = new HelloItemizedOverlay(drawable0, this);
JSONArray jArray = new JSONArray(result);
for(int i=0; i<jArray.length();i++){
JSONObject json = jArray.getJSONObject(i);
double d1 =json.getDouble("longtitude");
double d2 =json.getDouble("latitude");
GeoPoint point = new GeoPoint((int) (d2 * 1E6),
(int) (d1 * 1E6));
OverlayItem overlayItem0= new OverlayItem((GeoPoint) point, "Center", "Center");
itemizedoverlay0.addOverlay(overlayItem0);
}//for
mapOverlays.add(itemizedoverlay0);
mapView.getController().animateTo(point);
mc.setZoom(7);
}//try
mapOverlays.remove(itemizedoverlay0);
也不起作用。谢谢!
它仍然无法工作..在rm0()函数中我认为是问题。我写道:
public void rm0()
{
for(int i=0; i< mapOverlays.size();i++)
{
Toast.makeText(getBaseContext(), "in the rm0"+i,Toast.LENGTH_SHORT).show();
mapOverlays.remove(overlayItem0);
}
}
我怎样才能删除itemizedOverlay0?我试过了itemizedoverlay0.clearOverlay();也没有任何事情发生..
谢谢!
答案 0 :(得分:0)
更改populate()
。
ItemizedOverlay
按照以下方式更改方法:
public void removeOverlay(int item) {
mOverlays.remove(item);
populate();
}
public void clear() {
mOverlays.clear();
populate();
}
- 编辑 -
HelloItemizedOverlay itemizedoverlay0 = new HelloItemizedOverlay(drawable0, this);
try {
JSONArray jArray = new JSONArray(result);
for(int i=0; i<jArray.length();i++){
JSONObject json = jArray.getJSONObject(i);
double d1 =json.getDouble("longtitude");
double d2 =json.getDouble("latitude");
Drawable drawable0 = this.getResources().getDrawable(R.drawable.marker_default);
GeoPoint point = new GeoPoint((int) (d2 * 1E6), (int) (d1 * 1E6));
OverlayItem overlayItem0= new OverlayItem((GeoPoint) point, "Center", "Center");
itemizedoverlay0.addOverlay(overlayItem0);
}
mapOverlays.add(itemizedoverlay0);
mapView.getController().animateTo(point);
mc.setZoom(7);
}
此致