Android Google Maps v2 Camera Animation

So I'm not sure if this is a mistake or not yet ... maybe, or I may have missed something.

Anyway, here is a link to Google Maps V2 Camera Controls. https://developers.google.com/maps/documentation/android/views#moving_the_camera

Problem:

Animation to an already animated position does not call onFinish ();

How to replicate:

mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mLocation.getLatLng(), zoomLevel), 200, new GoogleMap.CancelableCallback() { @Override public void onFinish() { //DO some stuff here! Log.d("animation", "onFinishCalled"); } @Override public void onCancel() { Log.d("animation", "onCancel"); } }); 

This problem can occur when the user types twice what is called the same animation, even if there is a lot of time between them, onFinish will be called only for successful animation. When the camera is already installed, the onFinish method will not be called!

I could do the checks before doing the camera animation, but I don't like it as wasteful.

Any help would be greatly appreciated. Thanks.

+8
android animation camera google-maps-api-2
source share
4 answers

I have the same problem when I want to move the camera to the same position, this seems like an error. Even if the old and new positions do not match, and the difference is so small, for example: the old position .latitude = 94.54284009112, the new position .latitude = 94.54284003451, it does not work. my solution is to truncate the values ​​in order to get only old_position.latitude = new_position.latitude = 94.54, then I do the test.

There is another problem with moving the camera and scrolling the map at the same time, since I will disable the scroll gesture before moving and enable it on onFinish () and onCancel ().

 public void animateCameraTo(final double lat, final double lng) { _googleMap = getMap(); CameraPosition camPosition = _googleMap.getCameraPosition(); if (!((Math.floor(camPosition.target.latitude * 100) / 100) == (Math.floor(lat * 100) / 100) && (Math.floor(camPosition.target.longitude * 100) / 100) == (Math.floor(lng * 100) / 100))) { _googleMap.getUiSettings().setScrollGesturesEnabled(false); _googleMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lng)), new CancelableCallback() { @Override public void onFinish() { _googleMap.getUiSettings().setScrollGesturesEnabled(true); } @Override public void onCancel() { _googleMap.getUiSettings().setAllGesturesEnabled(true); } }); } } 

Hope this helps you;)

+15
source share

You should check the distance to the pixel, not the distance of the geometric:

 LatLngBounds myBounds = YOUR_BOUNDS; LatLngBounds visibleBounds = map.getProjection().getVisibleRegion().latLngBounds; Point myCenter = map.getProjection().toScreenLocation(myBounds.getCenter()); Point visibleCenter = map.getProjection().toScreenLocation(visibleBounds.getCenter()); int dist = (int) Math.sqrt(Math.pow(myCenter.x - visibleCenter.x, 2) + Math.pow(myCenter.y - visibleCenter.y, 2)); if (dist > YOUR_THRESHOLD) { map.animateCamera(CameraUpdateFactory.newLatLngBounds(myBounds, YOUR_PADDING), new GoogleMap.CancelableCallback() { @Override public void onFinish() { // do something } @Override public void onCancel() { // do something } }); } else { // do something } 
+2
source share

The only solution I found is to check for wasteful pixel values ​​by setting up the CameraUpdate object of a fake (but closing) object and making a nested animateCamera () call using fake CameraUpdate, and then calling another cameraUpdate () function in the first onFinish () with the correct CameraUpdate . I installed the Google MAP v2 update today, but that didn't help. This is a problem for rotating the device for me. I show bounding rectangles and the centroid does not change when rotating, so animateCamera () does not work, and when the device is rotated, the selected rectangle may be partially disconnected from the screen.

Did you find another solution? Thanks

0
source share

Here is another workaround:

Do you know the animation of your map animations. That way you can post a delayed runnable with a delay in the duration of the animation + some offset, and there you can check if the final / canceld listener was called ... if you cannot find it and call the appropriate listener

-one
source share

All Articles