0

我有一张地图,上面有很多点添加到 ItemizedOverlay。

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

有没有办法从 itemizedOverlay 中删除特定点?

例如,假设我在不同的纬度/经度上添加了很多点,我希望删除之前添加的纬度:32.3121212 和经度:33.1230912 的点。

我怎样才能删除这一点?

我真的需要这个,所以我希望有人能提供帮助。

谢谢。

完整的故事场景(如果您对如何解决这个问题有不同的想法):将事件添加到从数据库中捕获的地图。现在,当从数据库中删除事件时,我希望同步地图并仅删除已删除的事件。(请不要建议我重新下载除已删除的点之外的所有点,即使我已经想到了,但这不是我想做的选择。:p)

4

1 回答 1

4

使用 GeoPoints Array 创建 MapOverlay 并覆盖 draw 函数:

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

尝试谷歌一些谷歌地图教程,也许你会找到更多的解决方案。

于 2012-05-17T20:45:31.917 回答