我对使用 CameraUpdateFactory.newLatLngBounds() 的 moveCamera 和 animateCamera 的准确性有一些疑问。我比较了一个 LatLngBounds 对象,我创建并作为参数发送到 moveCamera/animateCamera (CameraUpdateFactory.newLatLngBounds()),映射.getProjection().getVisibleRegion().latLngBounds 在 onCameraChange() 事件甚至 GoogleMap.CancelableCallback#onFinish() . 他们不匹配。有人遇到过这个问题吗?这是一个错误吗?
我的代码是:
final LatLngBounds boundingBox = MapUtils.getBoundingBox(mCurrLocation.getLatitude(), mCurrLocation.getLongitude(), mCurrRadius);
try {
if (animate) {
map.animateCamera(CameraUpdateFactory.newLatLngBounds(boundingBox, 0),
new GoogleMap.CancelableCallback() {
@Override
public void onFinish() {
if (!boundingBox.equals(map.getProjection().getVisibleRegion().latLngBounds)) {
map.moveCamera(CameraUpdateFactory.newLatLngBounds(boundingBox, 0));
}
}
@Override
public void onCancel() {
}
});
} else {
map.moveCamera(CameraUpdateFactory.newLatLngBounds(boundingBox, 0));
}
}
请忽略我在这里比较两个对象的方式(等于)。我还调试了代码并检查了 2 个对象,发现它们不匹配 -
移动相机:
边界框 -
LatLngBounds{southwest=lat/lng: (32.08455383290544,34.773394063736845), north=lat/lng: (32.09730731777191,34.788375176773286)}
map.getProjection().getVisibleRegion().latLngBounds -
LatLngBounds{southwest=lat/lng: (32.084496299473756,34.77339383214712), north=lat/lng: (32.09736452396455,34.78837497532368)}
动画相机:
边界框 -
LatLngBounds{southwest=lat/lng: (40.70798493778415,-74.01434069136418),东北=lat/lng: (40.72072004852845,-73.99760391411343)}
map.getProjection().getVisibleRegion().latLngBounds -
LatLngBounds{southwest=lat/lng: (40.70798500292429,-74.01539381593466), north=lat/lng: (40.72071968970514,-73.99655096232891)}