我尝试使用osmbonuspack_v4.8 ilb
显示标记。
显示标记,但它放在屏幕的left-top
中。
我试图在中心设置,但不能。我不知道原因。
请告诉我最好的方法。
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);
}
答案 0 :(得分:2)
您可以尝试这种方式:
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);
}
我希望有所帮助!
答案 1 :(得分:1)
给它一个旋转。它应该将您的点绘制在屏幕的中心点。
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);