12

我使用以下代码以缩放级别显示单个标记,但它不会在地图上居中标记。只会显示一个标记:

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

此代码将其居中,但不提供任何缩放:

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

我需要居中和缩放。

4

3 回答 3

27

尝试以下

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

于 2013-07-12T09:32:36.627 回答
9

缩放的正确值在 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上查看

于 2013-07-12T09:38:42.580 回答
4

这是因为您需要将相机移动到CameraUpdateFactory您创建的位置,如下所示:

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

如果你不想要动画,那么你可以使用:

map.moveCamera(CameraUpdateFactory.newLatLng(latLng, 11);
于 2013-07-12T09:31:49.403 回答