Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android openstreetmap-如何在屏幕中央设置标记?_Android_Openstreetmap_Marker_Osmdroid - Fatal编程技术网

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

Android openstreetmap-如何在屏幕中央设置标记?,android,openstreetmap,marker,osmdroid,Android,Openstreetmap,Marker,Osmdroid,我正在尝试使用osmbonuspack\u v4.8 ilb显示标记。 标记已显示,但它位于屏幕的左上方。 我试着站在中间,但不行。我不知道原因 请告诉我最好的方法 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mapView = (Map

我正在尝试使用
osmbonuspack\u v4.8 ilb
显示标记。 标记已显示,但它位于屏幕的左上方。 我试着站在中间,但不行。我不知道原因

请告诉我最好的方法

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);

谢谢你的帮助,看起来不太对劲。专门设置地图视图的底部和右侧。位置是硬编码的什么?您是否试图在屏幕中心的横向/纵向位置放置图标?还是别的什么?