我试图执行动画来模拟地图上的路线,我必须显示一个带有标记的路径,逐个放置,等待X时间再放下一个。首先,我使用线程等待下一个标记,但它不会在任何设备上运行并在运行时在地图上中断,因此它会使用户体验如此糟糕。然后我决定使用animateCamera (Android API reference here)的回调功能来避免中断,但我找不到一些方法来制作动画,彼此之后,标记和位置的数量是不确定的,所以我必须重复。这是最后一个想法代码:
hashMarkers.get("Initial").setVisible(true);
mMap.animateCamera(CameraUpdateFactory.zoomTo(16), 5000, new GoogleMap.CancelableCallback() {
@Override
public void onFinish() {
for (COUNT=1; COUNT < hashMarkers.size() - 1;){
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(hashMarkers.get(String.valueOf(COUNT)).getPosition()) // Sets the center of the map to
.zoom(16) // Sets the zoom
.bearing(-bearing) // Sets the orientation of the camera to east
.tilt(90) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
hashMarkers.get(String.valueOf(COUNT)).setVisible(true);
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 3000, new GoogleMap.CancelableCallback() {
@Override
public void onFinish() {
COUNT++;
}
@Override
public void onCancel() {
}
});
此代码仅显示初始标记和hashmap中的第一个标记。
非常感谢您提供的有助于解决此问题的任何贡献!
答案 0 :(得分:1)
我找到了解决方案,创建了适用于我的可取消回调,可能对其他人有所帮助。
@Override
public void onFinish() {
CameraPosition cameraPosition2 = new CameraPosition.Builder()
.target(hashMarkers.get("Final").getPosition()) // Sets the center of the map to
.zoom(17) // Sets the zoom
.bearing(-bearing) // Sets the orientation of the camera to east
.tilt(90) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
hashMarkers.get("Final").setVisible(true);
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition2), 3000, new GoogleMap.CancelableCallback() {
@Override
public void onFinish() {
allView = new LatLngBounds(
allLatLng.get(0), allLatLng.get(allLatLng.size() - 1));
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(allView, 80), 2000, null);
}
@Override
public void onCancel() {
}
});
}
@Override
public void onCancel() {
}
GoogleMap.CancelableCallback FinalCancelableCallback = new GoogleMap.CancelableCallback(){
Jacj%25011987
};