Reputation: 493
I have a map with lots of points on it added to an ItemizedOverlay.
OverlayItem overlayItem = new OverlayItem(theGeoPoint, title, description);
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
Is there a way to remove a specific point from the itemizedOverlay?
Example, say I've added lots of point at different latitudes/longitudes and I wish to remove a point at latitude: 32.3121212 and longitude: 33.1230912, which was added earlier.
How can I remove JUST that point??
I really need this so I hope someone can help.
Thanks.
Full story scenario (in case you have a different idea on how to solve this): Adding events to a map that are caught from a database. Now when events are deleted from the database, I wish to sync the map and remove just those which were deleted. (please don't suggest I re-download all points excluding the deleted ones even though I've thought of that but it isn't an option concerning what I want to do. :p)
Upvotes: 0
Views: 334
Reputation: 7295
Create your MapOverlay with GeoPoints Array and override the draw function:
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);
}
}
}
}
(I didn't test above class)
and then in your MapActivity class you can just:
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setClickable(true);
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.add(mapOverlay);
Try google some GoogleMap tutorials and maybe you will find more solutions.
Upvotes: 4