我对于moveCamera和animateCamera以及CameraUpdateFactory.newLatLngBounds()的准确性有一些疑惑。我正在比较我创建并作为参数传递给moveCamera/animateCamera(CameraUpdateFactory.newLatLngBounds())的一个LatLngBounds对象,与onCameraChange()事件或GoogleMap.CancelableCallback#onFinish()中的map.getProjection().getVisibleRegion().latLngBounds。它们不匹配。是否有人遇到了这个问题?这是一个bug吗?
我的代码如下:
请忽略我在这里比较两个对象的方式(equals)。我也调试了代码并检查了两个对象,发现它们不匹配。
moveCamera:
- boundingBox: - LatLngBounds{southwest=lat/lng: (32.08455383290544,34.773394063736845), northeast=lat/lng: (32.09730731777191,34.788375176773286)} - map.getProjection().getVisibleRegion().latLngBounds: - LatLngBounds{southwest=lat/lng: (32.084496299473756,34.77339383214712), northeast=lat/lng: (32.09736452396455,34.78837497532368)}
animateCamera:
- boundingBox: - LatLngBounds{southwest=lat/lng: (40.70798493778415,-74.01434069136418), northeast=lat/lng: (40.72072004852845,-73.99760391411343)} - map.getProjection().getVisibleRegion().latLngBounds: - LatLngBounds{southwest=lat/lng: (40.70798500292429,-74.01539381593466), northeast=lat/lng: (40.72071968970514,-73.99655096232891)}
我的代码如下:
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));
}
}
请忽略我在这里比较两个对象的方式(equals)。我也调试了代码并检查了两个对象,发现它们不匹配。
moveCamera:
- boundingBox: - LatLngBounds{southwest=lat/lng: (32.08455383290544,34.773394063736845), northeast=lat/lng: (32.09730731777191,34.788375176773286)} - map.getProjection().getVisibleRegion().latLngBounds: - LatLngBounds{southwest=lat/lng: (32.084496299473756,34.77339383214712), northeast=lat/lng: (32.09736452396455,34.78837497532368)}
animateCamera:
- boundingBox: - LatLngBounds{southwest=lat/lng: (40.70798493778415,-74.01434069136418), northeast=lat/lng: (40.72072004852845,-73.99760391411343)} - map.getProjection().getVisibleRegion().latLngBounds: - LatLngBounds{southwest=lat/lng: (40.70798500292429,-74.01539381593466), northeast=lat/lng: (40.72071968970514,-73.99655096232891)}