2015-09-07 121 views
6

在我的Android應用程序中,我需要將標記放置在地圖上的確切位置。我在地圖上用51.507351,-0.127758(倫敦)的位置固定了一個標記。我使用下面的代碼來完成這項工作。android google map marker 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

試試這個:

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) | | | | | | | | | | *-----+-----+-----+-----*