我有一张地图,上面有很多点,加上了一个ItemizedOverlay。
OverlayItem overlayItem = new OverlayItem(theGeoPoint, title, description);
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);有办法从itemizedOverlay中删除特定的点吗?
例如,我在不同纬度/经度上添加了很多点,我希望去掉一个纬度: 32.3121212和经度: 33.1230912的点,这是前面添加的。
我怎么才能去掉这一点呢?
我真的需要这个所以我希望有人能帮上忙。
谢谢。
完整的故事场景(如果您对如何解决这个问题有不同的想法):将事件添加到从数据库捕获的映射中。现在,当从数据库中删除事件时,我希望同步映射并删除那些被删除的事件。(请不要建议我重新下载所有的点,不包括删除的,即使我已经想到了,但这不是一个选项,我想做什么。::p)
发布于 2012-05-17 20:45:31
使用MapOverlay数组创建GeoPoints并重写GeoPoints函数:
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教程,也许你会找到更多的解决方案。
https://stackoverflow.com/questions/10643146
复制相似问题