Google Maps Android Studio - how disable the map controls?

房东的猫 提交于 2020-06-23 08:53:25

问题


I'm working in Android Studio with MapsActivity. Everything works fine, but how do I disable the map controls that show up on top of the Google map?

Here is my code:

public class MapsActivity extends FragmentActivity {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        setUpMapIfNeeded();
    }
    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }
    private void setUpMapIfNeeded() {

        if (mMap == null) {

            mMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
            if (mMap != null) {
                setUpMap();
            }
        }
    }
    private void setUpMap() { 
  
mMap.addMarker(new MarkerOptions()
  .position(new LatLng(46.066185, 19.674654))
  .title("Novo naselje okretnica ")
  .icon(BitmapDescriptorFactory.fromResource(R.drawable.bluebus2)));
        }

Check out the image, to see what I'm talking about.

So there is the problem, I don't want those map controls. Please help me figure out how to disable this. Thx :)


回答1:


Thank you @Coeffect! It works!

public class MapsActivity extends FragmentActivity {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    setUpMapIfNeeded();
    mMap.setMyLocationEnabled(true);
    mMap.getUiSettings().setMapToolbarEnabled(false);
}



回答2:


From https://developers.google.com/maps/documentation/android/interactivity#map_toolbar

By default, a toolbar appears at the bottom right of the map when a user taps a marker. The toolbar gives the user quick access to the Google Maps mobile app.

You can enable and disable the toolbar by calling UiSettings.setMapToolbarEnabled(boolean).



来源:https://stackoverflow.com/questions/30655421/google-maps-android-studio-how-disable-the-map-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!