5

Hi I would like to know how to disable the north align compass button in the top left corner of Google Maps. I linked an image to show what I am talking about. I have found out how to disable other UI components but I find nothing about disabling this button. I am using android studio.

enter image description here

Thanks!

2 Answers 2

21

The UiSettings object of maps has a setCompassEnabled() method that you can use to enable or disable the realign north button.

https://developers.google.com/android/reference/com/google/android/gms/maps/UiSettings

The simple activity that shows how to do it

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }


    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        mMap.getUiSettings().setCompassEnabled(false);

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}
2

TO Hide compass Just add this line where you are loading google map

        mMap.getUiSettings().setCompassEnabled(false);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.