public class CustomBalloonItemizedOverlay extends
BalloonItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> m_overlays = new ArrayList<OverlayItem>();
private Context c;
public MyFavoritePlacesItemizedOverlay(Drawable defaultMarker,
MapView mapView) {
super(boundCenter(defaultMarker), mapView);
c = mapView.getContext();
}
public void addOverlay(OverlayItem overlay) {
m_overlays.add(overlay);
populate();
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
if (!shadow) {
super.draw(canvas, mapView, false);
}
}
public void removeOverlay(OverlayItem overlay) {
m_overlays.remove(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return m_overlays.get(i);
}
@Override
public int size() {
return m_overlays.size();
}
@Override
protected boolean onBalloonTap(int index, OverlayItem item) {
// Your code...
return true;
}
}
下面是如何使用它...
initGeoPoint = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
mapOverlays = myMapView.getOverlays();
drawableImage = this.getResources().getDrawable(R.drawable.any_icon);
CustomBalloonItemizedOverlay customItemizedOverlayObject = new public class CustomBalloonItemizedOverlay(
drawableImage, myMapView);
OverlayItem overlayItem = new OverlayItem(initGeoPoint, name,
address);
customItemizedOverlayObject.addOverlay(overlayItem);
mapOverlays.add(customItemizedOverlayObject);
}