我想知道是否有机会Overlay
在谷歌地图中设置决赛。我想这样设置我的十字准线,这样它在缩放时就不会移动。
代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_view);
initData();
mapView = (MapView) findViewById(R.id.mapView);
mapView.setSatellite(true);
mapView.setTraffic(true);
mapView.setBuiltInZoomControls(true);
controller = mapView.getController();
controller.animateTo(coordinate);
controller.setZoom(18);
// TODO:
CrossHairsOverlay chOverlay = new CrossHairsOverlay();
// Pin
MapOverlay mapOverlay = new MapOverlay();
mapOverlay.setPointToDraw(coordinate);
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
listOfOverlays.add(chOverlay);
}
十字线:
public class CrossHairsOverlay extends Overlay {
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
super.draw(canvas, mapView, shadow);
Projection projection = mapView.getProjection();
Point centerPoint = projection.toPixels(mapView.getMapCenter(), null);
Bitmap crossHairs = BitmapFactory.decodeResource(getResources(), R.drawable.cross_hair);
canvas.drawBitmap(crossHairs, centerPoint.x - (int)(27 * dpi + 0.5f), centerPoint.y - (int)(27 * dpi + 0.5f), new Paint());
return true;
}
}
如果我以这种方式使用它,它会在缩放完成后重新定位。左/右拖动正确。我真的不想设置“ZoomListener”并一直重绘。我希望有一个更好的解决方案来做到这一点。
谢谢