2013-07-12 45 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

所以你可能想删除重复的答案。 –