0

ItemizedOverlay に追加された多数のポイントを含むマップがあります。

OverlayItem overlayItem = new OverlayItem(theGeoPoint, title, description);
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);

itemizedOverlay から特定のポイントを削除する方法はありますか?

例として、さまざまな緯度/経度に多数のポイントを追加した後、以前に追加された緯度: 32.3121212 および経度: 33.1230912 のポイントを削除したいとします。

そのポイントだけを削除するにはどうすればよいですか??

私は本当にこれが必要なので、誰かが助けてくれることを願っています.

ありがとう。

完全なストーリーのシナリオ (これを解決する方法について別の考えがある場合): データベースから取得したイベントをマップに追加します。イベントがデータベースから削除されたら、マップを同期して、削除されたものだけを削除したいと考えています。(削除したものを除いてすべてのポイントを再ダウンロードすることを提案しないでください.

4

1 に答える 1

4

GeoPoints Array を使用して MapOverlay を作成し、描画関数をオーバーライドします。

public class MapOverlay extends Overlay 
{

    private ArrayList<GeoPoints>points;
    ...


    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) 
    {
            super.draw(canvas, mapView, shadow);      
            int len = points.size();  
            if(len > 0)
            {
                for(int i = 0; i < len; i++)
                {
                   // do with your points whatever you want
                   // you connect them, draw a bitmap over them  and etc.
                   // for example:
                   Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.pointer);
                   mapView.getProjection().toPixels(points.get(i), screenPts);
                   canvas.drawBitmap(bmp, screenPts.x-bmp.getWidth()/2, screenPts.y - bmp.getHeight()/2, null);  
                } 
            }
    }

    public void addPoint(GeoPoint p)
    {
       // add point to the display array
    }

    public void removePointByIndex(int i)
    {
       points.remove(i);
    }

    public void removePointByCordinate(Double lat, Double lng)
    {
        int index = -1;
        int len = points.size();  
        if(len > 0)
        {
                for(int i = 0; i < len; i++)
                {
                     if((int)(lat*1E6) == points.get(i).getLatitudeE6() && (int)(lng*1E6) == points.get(i).getLongitudeE6())
                     {
                          index = i;
                     }
                } 
            }

            if(index != -1)
            {
                points.remove(index);
            }
        }
    }

    public void removePoint(GeoPoint p)
    {
        int index = -1;
        int len = points.size();  
        if(len > 0)
        {
                for(int i = 0; i < len; i++)
                {
                     if(p == points.get(i))
                     {
                          index = i;
                     }
                } 
            }

            if(index != -1)
            {
                points.remove(index);
            }
        }
    }

}

(私はクラスの上でテストしませんでした)

次に、MapActivity クラスで次のことができます。

MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setClickable(true);
MapOverlay mapOverlay = new MapOverlay();                       
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.add(mapOverlay);

いくつかの GoogleMap チュートリアルをグーグルで試してみてください。おそらく、より多くの解決策が見つかるでしょう。

于 2012-05-17T20:45:31.917 に答える