首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从GeoPoint中删除特定的ItemizedOverlay?

从GeoPoint中删除特定的ItemizedOverlay?
EN

Stack Overflow用户
提问于 2012-05-17 20:38:08
回答 1查看 323关注 0票数 0

我有一张地图,上面有很多点,加上了一个ItemizedOverlay。

代码语言:javascript
复制
OverlayItem overlayItem = new OverlayItem(theGeoPoint, title, description);
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);

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

例如,我在不同纬度/经度上添加了很多点,我希望去掉一个纬度: 32.3121212和经度: 33.1230912的点,这是前面添加的。

我怎么才能去掉这一点呢?

我真的需要这个所以我希望有人能帮上忙。

谢谢。

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

EN

回答 1

Stack Overflow用户

发布于 2012-05-17 20:45:31

使用MapOverlay数组创建GeoPoints并重写GeoPoints函数:

代码语言:javascript
复制
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类中,您只需:

代码语言:javascript
复制
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setClickable(true);
MapOverlay mapOverlay = new MapOverlay();                       
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.add(mapOverlay);

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

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10643146

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档