1

我按照你告诉我的做了。我会撒谎问在 oncreate() 里面是否应该放一些东西,除了 from
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;`

对所有类别的标记使用相同的地理点变量(点)是否有问题?为了将叠加项目添加到我所做的每个类别中:

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(); 也是,但什么也没发生..

谢谢!

4

1 回答 1

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);
}

问候

于 2012-12-12T19:55:59.200 回答