I want to geocode address as soon as map center has been changed.
How can I handle map moveend with new Google Maps for Android V2? (I'm talking about the case then user drags map by finger)
I want to geocode address as soon as map center has been changed.
How can I handle map moveend with new Google Maps for Android V2? (I'm talking about the case then user drags map by finger)
On camera idle is what you should use now
OUTDATED Use the new maps API instead. See answer from punksta.
After using AZ13's solution above, and running into the problem mentioned in the comments, I created the following solution, that solves the issue more reliably. However, since I am using a timer after the onRelease event to determine whether the map is still animating, there is a slight delay in this solution.
The code can be found on Github via this link: https://github.com/MadsFrandsen/MapStateListener
My solution can be used from an activity in the following way:
Check out new maps api.
developers.google.com sample
Starting with play-services-maps 9.4.0 you can simply use
GoogleMap.OnCameraMoveStartedListener
,GoogleMap.OnCameraMoveListener
andGoogleMap.OnCameraIdleListener
.If, for some reason, you want to use the older API which is now deprecated you can use
onCameraChangeListener
. But you have to be aware of two things:onCameraChange()
might be called many times while you drag the map OR only once (when dragging stopped).onCameraChange()
can be slightly different from the final camera position.The following code takes both issues into account:
The simplest way is to use setOnCameraIdleListener method to handle your move end state of touch listener on your map fragment. see the example below:
I would try a onCameraChangeListener. The listener is called every time a movement of the camera is finished. The listener will also give you the new location. In my tests the listener was called pretty often during dragging maybe there is a better solution.