Reputation: 47387
Is there any way to detect when a GoogleMaps map begins moving / begins camera change when the change is not initiated by user input?
I know I can tap into the touch events for when a user manually moves it, but I can't find where to tap into any event that is triggered programmatically.
So if I call something like this
_nativeMap.AnimateCamera(CameraUpdateFactory.NewLatLng(newCameraLocation), _animationDuration, null);
The only event that I see raised is CameraChange
which only happens after the change is complete.
I really need some way to detect when it begins moving.
note: this example is Xamarin / C# but I don't really care about that.
Upvotes: 1
Views: 1163
Reputation:
I am not sure if it is efficient. But maybe you can use a handler to check each x seconds if the maps is still centered at the same position.
Lets say you have
LatLng lastPosition;
Use a handler like this:
Handler h = new Handler();
int delay = REFRESH_RATE;
h.postDelayed(new Runnable(){
public void run(){
LatLng newPosition = mapView.getCameraPosition().target;
double distance = computeDistance(newPosition, lastPosition);
if(distance > THRESHOLD)
//Camera moved.
h.postDelayed(this, delay);
}
}, delay);
Now you need to define the refresh rate, and the minimum distance to conclude that you have a movement. You need to find a way to compute distances too, Location has a built-in method...
You can use this handler after animateCamera() and cancel it on Animation onFinish().
Upvotes: 1