使用 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);
尝试谷歌一些谷歌地图教程,也许你会找到更多的解决方案。