2016-09-02 15 views
2

osmbonuspack_v4.8 ilbを使用してマーカーを表示しようとしています。 マーカーが表示されましたが、画面のleft-topに配置されています。 に設定しようとしていますが、できません。私はその理由を知らない。openstreetmap - 画面の中央にマーカーを設定するにはどうすればいいですか?

最善の方法を教えてください。

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

何ですか?画面中央の緯度/経度にアイコンを配置しようとしていますか?または、他の何か? – spy

答えて

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

私はそれが役に立てば幸い!

+0

ありがとうございました。 –

+1

が正しく表示されません。地図の設定は、具体的には下部と右側を表示します。場所はハードコードされています – spy

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); 
関連する問題