0

When I rotate the map, the compass appears. However one of my button overlaps with the compass... I'm wondering if there's a way to detect it so I can hide my button when the compass show. Thanks in advance!

Edit: My question was misleading earlier sorry, I actually want the button to disappear when user is actually rotating/tilting the map, and it should reappear once user's hand is off the screen.

@MaciejGórski 's suggestion of using CameraPosition.bearing != 0 || CameraPosition.tilt != 0 is a big step to me, I tried the following implementation but then I realize that OnCameraChangeListener doesn't fire as soon as user start rotating/tilting the map, so it won't work as expected.

public OnCameraChangeListener getCameraChangeListener() {
    return new OnCameraChangeListener() {
        @Override
        public void onCameraChange(CameraPosition position) {


            // when compass show hide option button
            if (optionButton.getVisibility() == LinearLayout.VISIBLE
                    && (position.bearing != 0 || position.tilt != 0)) {
                optionButton.setVisibility(LinearLayout.GONE);

                final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                //wait 1 sec and show the button again
                            optionButton.setVisibility(LinearLayout.VISIBLE);
                    }
                }, 1000);
            }

        }
    };
}
Arch1tect
  • 4,128
  • 10
  • 48
  • 69

2 Answers2

1

You can easily detect when compass shows up by checking CameraPosition.bearing != 0 || CameraPosition.tilt != 0 in OnCameraChangeListener.

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94
  • thank you, it's very helpful but my question is a little more complex. Please see the update.. – Arch1tect Jun 16 '13 at 13:07
  • @Arch1tect How about trying to use polling? In onResume send a message to Handler and after handling, send delayed message. Inside handleMessage use map.getCameraPosition(). Don't forget to remove message in onPause to avoid memory leak. – MaciejGórski Jun 17 '13 at 07:00
  • I don't quite follow here, why it has to do with onResume... Also what about the problem `onCameraChangeListerner` not responsive enough? http://stackoverflow.com/questions/14235686/oncamerachangelistener-is-not-responsive-enough-is-there-another-way – Arch1tect Jun 17 '13 at 12:19
  • @Arch1tect Polling is about ignoring `onCameraChangeListener`, which is a push-like notification. Instead you have some code (`handleMessage`) called periodically, where you retrieve current `CameraPosition` value. – MaciejGórski Jun 17 '13 at 14:05
0

I don't think this option exist, you would be better with relocating your button or removing the compass widget of the map with this line:

 myMap.getUiSettings().setCompassEnabled(false);
Emil Adz
  • 40,709
  • 36
  • 140
  • 187