george_mx george_mx - 3 months ago 19
Android Question

Google Maps opens after click on MapView v2

I have been struggling to make the MapView not clickable. I hope someone faced this problem too.

Here's my code:

<com.google.android.gms.maps.MapView
android:id="@+id/map_header"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:clickable="false"
android:longClickable="false"
map:liteMode="true"
map:mapType="normal"
/>


Also:

mMap.getUiSettings().setAllGesturesEnabled(false);
mMap.getUiSettings().setMapToolbarEnabled(false);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(userLocation)
.zoom(16)
.build();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
mProgressBar.setVisibility(View.GONE);


This only happens when I'm using lite mode. On normal mode, it isn't clickable.

Thanks in advance :)

Answer Source

Considering you are using it in an activity. You can do the following

public class MapActivity extends AppCompatActivity implements OnMapReadyCallback {

    MapView mapView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);

        // Gets the MapView from the XML layout and creates it
        mapView = (MapView) v.findViewById(R.id.map_header);
        mapView.setClickable(false);
        mapView.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap map) {
        // Perform action on your map. E.g. Display marker 
    }
}