问题
I need to listen CameraPosition changes to draw a custom compass. The problem that: GoogleMap.OnCameraChangeListener onCameraChange
- this listener may not be notified of intermediate camera positions.
- it fires with random delays (can not understand why)
Is there are any way to listen to CameraPosition bearing changes? (In ios f.e. it's possible to achieve using Key-Value Observing), reflection...? Thanks.
回答1:
Put FrameLayout above map and catch touches:
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mCatchTouchFrameLayoutListener != null)
mCatchTouchFrameLayoutListener.onTouch(ev);
return false;
}
回答2:
To move the camera instantly with the given CameraUpdate, you can call GoogleMap.moveCamera(CameraUpdate)
.
You can make the user experience more pleasing, especially for short moves, by animating the change. To do this instead of calling GoogleMap.moveCamera()
call GoogleMap.animateCamera()
. The map will move smoothly to the new attributes. The most detailed form of this method, GoogleMap.animateCamera(cameraUpdate, duration, callback)
, offers three arguments:
CameraUpdate: The CameraUpdate describing where to move the camera.
Callback: An object that implements GoogleMap.CancellableCallback. This generalized interface for handling tasks defines two methods
onCancel()
andonFinished()
. For animation, the methods are called in the following circumstances: onFinish() Invoked if the animation goes to completion without interruption. onCancel() Invoked if the animation is interrupted by calling stopAnimation() or starting a new camera movement. Alternatively, this can also occur if you call GoogleMap.stopAnimation().Duration: Desired duration of the animation, in milliseconds, as an
int
.
来源:https://stackoverflow.com/questions/28819522/googlemap-oncamerachangelistener-oncamerachange-works-with-delays