2013-07-12 44 views
7

我使用以下代碼在縮放級別顯示單個標記,但它不會將地圖標記放在地圖上。只有一個標記將永遠顯示:在Android中置中地圖標記

LatLng latLng = new LatLng(Latitude, Longitude); 
cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 11.0f); 

該代碼將圍繞它,但它不提供任何變焦:

LatLngBounds bounds = latLngBuilder.build(); 
cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, 30); 

我需要中心和縮放。

回答

7

用於變焦的正確值是2.0和22.00之間。

此之後,你已經加入這一行

GoogleMap mMap; 
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(latlng, 10)); 

關於放大你可以從文檔閱讀本 變焦:所需的縮放水平,在2.0至21.0。低於這個範圍的值被設置爲2.0,並且高於它的值被設置爲21.0。增加要放大的值。並非所有區域都具有最大縮放級別的圖塊。

您可以檢查這在http://developer.android.com/reference/com/google/android/gms/maps/CameraUpdateFactory.html

3

,這是因爲你需要你的相機移動到CameraUpdateFactory創建,像這樣:

LatLng latLng = new LatLng(Latitude, Longitude); 
map.animateCamera(CameraUpdateFactory.newLatLng(latLng, 11); 

,如果你不想要的動畫,那麼你可以只使用:

map.moveCamera(CameraUpdateFactory.newLatLng(latLng, 11); 
+4

CameraUpdateFactory.newLatLng(的latLng,11.0f)是無效的。該方法不需要縮放參數。你需要newLatLngZoom – AndroidDev

+0

是的我錯過了他浮雕浮雕變焦的事實。 –

21

請嘗試以下

LatLng coordinate = new LatLng(Latitude, Latitude); 
CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(coordinate, 11.0f); 
map.animateCamera(yourLocation); 

你也可以做到這一點(更清潔的方式)

CameraPosition cameraPosition = new CameraPosition.Builder() 
    .target(Latitude, Latitude) // Center Set 
    .zoom(11.0f)    // Zoom 
    .bearing(90)    // Orientation of the camera to east 
    .tilt(30)     // Tilt of the camera to 30 degrees 
    .build();     // Creates a CameraPosition from the builder 
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 

https://developers.google.com/maps/documentation/android/views?hl=fr-FR#moving_the_camera

+0

我已經給出了這個答案。 –

+0

是的,我發佈後看到它 – eMi

+0

所以你可能想刪除重複的答案。 –