我在onmapready()中添加了相机位置和动画回调。
CameraPosition cameraPosition =
new CameraPosition.Builder()
.target(new LatLng(currentRoute.locations.get(1).getLatitude(),
currentRoute.locations.get(1).getLongitude()))
.tilt(60)
.bearing((float)currentRoute.getRouteEdges().getFirst().getHeading(currentRoute.getStart(), currentRoute.getFinish())-40)
.zoom(20)
.build();
CameraUpdate update = (CameraUpdateFactory.newCameraPosition(cameraPosition));
turnByTurnMap.animateCamera(update, new GoogleMap.CancelableCallback() {
@Override
public void onFinish() {
if(currentPosition<currentRoute.locations.size()-1){
float bearing = HelperMethods.latLongToLocationDouble(currentRoute.locations.get(currentPosition).getLatitude(),
currentRoute.locations.get(currentPosition).getLongitude()).bearingTo(HelperMethods.latLongToLocationDouble(currentRoute.locations.get(currentPosition+1).getLatitude(),
currentRoute.locations.get(currentPosition+1).getLongitude()));
CameraPosition cameraPosition =
new CameraPosition.Builder()
.target(new LatLng(currentRoute.locations.get(currentPosition).getLatitude(),
currentRoute.locations.get(currentPosition).getLongitude()))
.tilt(60)
.bearing(bearing)
.zoom(20)
.build();
currentPosition++;
}
}
@Override
public void onCancel() {
}
});
为什么相机不沿着这些位置移动。位置数组中有8个位置。为什么相机不更新?
编辑:我已经将animatecamera添加到回调中,但是回调从未被调用我重新发布了当前的实现,我在回调中记录了日志,它从未被调用?
CameraPosition cameraPosition =
new CameraPosition.Builder()
.target(new LatLng(currentRoute.locations.get(1).getLatitude(),
currentRoute.locations.get(1).getLongitude()))
.tilt(60)
.bearing((float)currentRoute.getRouteEdges().getFirst().getHeading(currentRoute.getStart(), currentRoute.getFinish())-40)
.zoom(20)
.build();
CameraUpdate update = (CameraUpdateFactory.newCameraPosition(cameraPosition));
turnByTurnMap.animateCamera(update,
3000,
routeAnimationCancelableCallback);
routeAnimationCancelableCallback = new GoogleMap.CancelableCallback() {
@Override
public void onCancel() {
}
@Override
public void onFinish() {
Log.d(TAG, "onFinish: here");
if(currentPosition<currentRoute.locations.size()-1){
float bearing = HelperMethods.latLongToLocationDouble(currentRoute.locations.get(currentPosition+1).getLatitude(),
currentRoute.locations.get(currentPosition+1).getLongitude()).bearingTo(HelperMethods.latLongToLocationDouble(currentRoute.locations.get(currentPosition+1).getLatitude(),
currentRoute.locations.get(currentPosition+2).getLongitude()));
CameraPosition cameraPosition =
new CameraPosition.Builder()
.target(new LatLng(currentRoute.locations.get(currentPosition+1).getLatitude(),
currentRoute.locations.get(currentPosition+1).getLongitude()))
.tilt(60)
.bearing(bearing)
.zoom(10)
.build();
CameraUpdate update = (CameraUpdateFactory.newCameraPosition(cameraPosition));
turnByTurnMap.animateCamera(update,
3000,
routeAnimationCancelableCallback);
currentPosition++;
}
}
};
1条答案
按热度按时间v1l68za41#
考虑到第二个代码,只需将初始调用移动到
animateCamera
设置后routeAnimationCancelableCallback
. 这还包括要调用的初始修复animateCamera
在回调中。