【发布时间】:2015-11-26 13:04:12
【问题描述】:
我需要同时使用 CameraPosition 和 CameraBounds 的一些功能,就像我的具体要求是在轴承上移动相机并将其倾斜几度,以及地图上我想要覆盖的其他标记我执行相机更新。
CameraUpdateFactory 类有两个不同的方法用于两个不同的目的。
1) newCameraPosition 2) newLatLngBounds
但我怀疑我是否可以同时使用它们来获得我想要的结果。
CameraPosition 的工作原理如下:
LatLng current_lat_lng=new LatLng(lat, lon);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(current_lat_lng) // Sets the center of the map to Mountain View
.zoom(googleMap.getCameraPosition().zoom) // Sets the zoom
.bearing((float)mapHeading) // Sets the orientation of the camera to a bearing
.tilt(0) // Sets the tilt of the camera to 0 degrees
.build();
googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
CameraBounds 的工作方式如下:
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
if (marker_Searched != null) {
builder.include(marker_Searched.getPosition());
}
if (marker_selected_taxi != null) {
builder.include(marker_selected_taxi.getPosition());
}
LatLngBounds bounds = builder.build();
int padding = 300; // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
googleMap.moveCamera(cu);
有没有人尝试过任何解决方法?
【问题讨论】:
-
你为什么不一个接一个地使用?
-
@Androiderson :由于两次相机移动(一次具有单个位置,一次具有位置边界)而产生抖动效果
-
为避免出现问题,请尝试在第二个上使用
animateCamera。
标签: android google-maps android-maps-v2