openstreetmap - 如何在屏幕中央设置标记?

openstreetmap - How to set marker in center of screen?

我正在尝试使用 osmbonuspack_v4.8 ilb 显示标记。 显示了标记,但它位于屏幕的 left-top 中。 我正在尝试 set 居中但不能。我不知道原因。

请告诉我最好的方法。

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mapView.setMultiTouchControls(true);

        mapView.setTileSource(TileSourceFactory.MAPNIK);
        mapController = (MapController) this.mapView.getController();
        mapController.setZoom(15);
        GeoPoint center = new GeoPoint(52.221, 6.893);
        mapController.animateTo(center);
        //mapController.setCenter(center);

        //--- Create Overlay
        addMarker(center);

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}

你可以这样试试:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mapView.setMultiTouchControls(true);

        DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

        int width = displayMetrics.widthPixels;
        int height = displayMetrics.heightPixels;
        mapView.setBottom(height);
        mapView.setRight(width);
        mapView.setTileSource(TileSourceFactory.MAPNIK);
        mapController = (MapController) this.mapView.getController();
        mapController.setZoom(15);
        GeoPoint center = new GeoPoint(52.221, 6.893);
        mapController.animateTo(center);
        //mapController.setCenter(center);

        //--- Create Overlay
        addMarker(center);

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}

希望对您有所帮助!

试一试。它应该将您的点绘制在屏幕的中心点。

        DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

        int width = displayMetrics.widthPixels;
        int height = displayMetrics.heightPixels;

        IGeoPoint pt = mMapView.getProjection().fromPixels(width/2, height/2);
        mapView.getController().animateTo(pt);

        //--- Create Overlay
        addMarker(pt);