A
A
Andrey Valitov2018-03-05 19:36:41
Android
Andrey Valitov, 2018-03-05 19:36:41

Why isn't the mapView displayed in the fragment when navigating to it?

Hello everybody!
This is my first time making an app with maps. The bottom line is this: there is a Navigation Drawer and a few (so far) fragments. Before that, I used maps through Activity, now I switched to Fragment and then added mapView in the xml markup of this fragment: as a result, the map is not displayed when you click on the Menu Item element (direct navigation), the application itself on the smartphone does not crash, just a white screen. On the map in the future I'm going to add labels from SQLlite, so I need the ability to manipulate the code in the map class.
Markup:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.498"
        tools:ignore="MissingConstraints" />
</android.support.constraint.ConstraintLayout>

Class code:
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.OnMapReadyCallback;

public class CustomMapFragment extends Fragment implements OnMapReadyCallback {

    private MapView mapView;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_map, container, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Activity activity = this.getActivity();
        mapView = activity.findViewById(R.id.mapView);
        mapView.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {

    }
}

Manifest Permissions:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.provides.gsf.permission.READ_GSERVICES" />

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Pavlovsky, 2018-03-06
@TranE91

<com.google.android.gms.maps.MapView
android:layout_width="0dp"
android:layout_height="0dp"

Is this the norm in ConstrintLayout ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question