我创建了一个扩展 Osmdroid (CustomOverlay.java) 中的 Overlay 类的类。但是,在使用 CustomOverlay.java 的主要活动上调用方法 createMark() 后,地图上没有出现任何内容。我不想使用 ItemizedOverlay 类。
任何想法?
CustomOverlay.java(扩展 Overlay 的类)
public CustomOverlay(Context context) {
super(context);
}
@Override
protected void draw(Canvas canvas, MapView mapView, boolean shadow) {
Point screenPoint = new Point();
mapView.getProjection().toPixels(geoPoint, screenPoint);
super.drawAt(canvas, mapView.getResources().getDrawable(R.drawable.marker), screenPoint.x, screenPoint.y, shadow);
}
}
这是我在主要活动中调用的方法:
private void createMarker() {
List<Overlay> mapOverlays = mMapView.getOverlays();
Overlay c = new CustomOverlay(this);
mapOverlays.add(c);
mMapView.invalidate();
}
回答:
@Override
protected void draw(Canvas canvas, MapView mapView, boolean shadow) {
Point screenPoint = new Point();
mapView.getProjection().toPixels(geoPoint, screenPoint);
Bitmap marker= BitmapFactory.decodeResource(mapView.getResources(), R.drawable.marker);
canvas.drawBitmap(marker, screenPoint.x, screenPoint.y, null);
}