2015-09-07 6 views
6

私のAndroidアプリケーションでは、マップ上の正確な位置にマーカーを配置する必要があります。私は51.507351、-0.127758(ロンドン)の位置で地図上にマーカーを固定します。私は次のコードを使って作業をしました。android google map markerを配置する

googleMap.addMarker(new MarkerOptions().position(
     new LatLng(51.507351, -0.127758)).icon(
     BitmapDescriptorFactory.fromBitmap(BitmapFactory 
       .decodeResource(getResources(), 
         R.drawable.q_icon)))); 
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
     new LatLng(51.507351, -0.127758), 20)); 

そして、この私のマーカー描画イメージ:

enter image description here

今私の問題は、 "Q" のシンボルが51.507351、-0.127758の位置に配置されています。下の矢印が始まる位置にマーカーを置く必要があります。

私の質問を理解できるように画像をご覧ください。

どうすればいいですか?私を助けてください。

enter image description here

答えて

0

private GoogleMap mMap; 

mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 

mMap.addMarker(new MarkerOptions() 
    .position(new LatLng(0, 0)) 
    .title("Hello world") 
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))); 
1

はこの1つを試してみてください:

googleMap.addMarker(new MarkerOptions().position(
       new LatLng(51.507351, -0.127758)).icon(
       BitmapDescriptorFactory.fromBitmap(BitmapFactory 
         .decodeResource(getResources(), 
           R.drawable.q_icon))).anchor(0.5f, 1f)); 
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
    new LatLng(51.507351, -0.127758), 20)); 
+0

ここには作業しました。 Spaciba o_O – statosdotcom

11

マーカーが固定されている方法の背後にあるロジックのようなものです。また、あなたのビットマップリソースに基づいて考慮して

0,0 0.5,0.0 1,0 *-----+-----+-----+-----* | | | | | | | | | | 0,0.5 +-----+-----+-----+-----+ 1,0.5 | | | X | | (U, V) = (0.7, 0.6) | | | | | *-----+-----+-----+-----* 0,1 0.5,1.0 1,1

、それはあなたが希望よりも少し異なって配置することができます彼らが実際に最も近いスナップ位置に近似しているからです。上の例では、アンカーポイントはこの位置にスナップします。 *-----+-----+-----+-----* | | | | | | | | | | +-----+-----+-----X-----+ (X, Y) = (3, 1) | | | | | | | | | | *-----+-----+-----+-----*

関連する問題