1

I want to determine whether the camera changed event was initiated from the user or not. (i have to make different actions based on that). So if the user pans a camera with the finger, i have to close sg, but if i moved the camera with the API, i do not.

Currently i cannot decide it was a user event or not, in my OnCameraChangeListener, because the onCameraChange(CameraPosition var1) method does not provide any kind of information about that.

I also tried to save the last marker position which i animated onto programmatically, and check that in the listener method:

map.setOnCameraChangeListener(new GoogelMap.onCameraChangeListener {
    public void onCameraChange(CameraPosition position) {
            if (!cameraPosition.target.equals(lastClickedMarker)) {
                // this is a user event
            }
}

I set the lastClickedMarker with the OnMarkerClickListener. I found out i cannot rely on this, because the cameraPosition and lastClickedMarker coordinates will always differ a little, even if really animate to that marker programmatically with animateCamera().

Is there any way to solve this?

WonderCsabo
  • 11,947
  • 13
  • 63
  • 105

1 Answers1

1

You can set a boolean before you change the camera programatically, and check if it is set (and unset) in the onCameraChange method.

Something like this:

// Moving programmatically
cameraMovedProgrammatically = true;
map.animateCamera(cameraUpdate);

And checking it:

public void onCameraChange(CameraPosition position) {
    if (cameraMovedProgrammatically) {
        // this is not a user event
        cameraMovedProgrammatically = false;
    } else {
        // this is a user event
    }
}
hunyadym
  • 2,213
  • 25
  • 39
  • You need to be careful with cameraUpdates, that do not really change the position. In that case onCameraChange will not be called and the next manual move will look like a programmatically started move. I am also not sure what happens if an animated programmatic move is intercepted by a manual move (while animation is still running). I don't think onCameraChange will then be called twice. – user2808624 Oct 11 '15 at 19:23
  • 1
    I would reset the flag cameraMovedProgrammatically in addition when a touchEvent is detected, to avoid the problems mentioned in my previous comment. (It was too late to edit the comment) – user2808624 Oct 11 '15 at 19:32