Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve method "getMapAsync"

Excuse me for any grammatical errors. I followed a tutorial to view the google map in a fragment, but something has gone wrong.

this is my file .java that is hooked with the fragment:

public class MapFragment extends Fragment implements OnMapReadyCallback{
@Nullable
@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 onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    MapFragment fragment = (MapFragment)getChildFragmentManager().findFragmentById(R.id.map);
    fragment.getMapAsync(this); //Here i get the error
}

@Override
public void onMapReady(GoogleMap googleMap) {

}

}

This is the layout fragment:

<fragment
    android:id="@+id/map"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.MapFragment"></fragment>

What did I do wrong?

Thank you!

like image 436
Jr Antonio Avatar asked Sep 06 '25 23:09

Jr Antonio


1 Answers

You have to use SupportMapFragment rather than MapFragment
in XML

<fragment
    android:id="@+id/map"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"></fragment>

in Fragment

SupportMapFragment fragment = (SupportMapFragment)getChildFragmentManager().findFragmentById(R.id.map);
fragment.getMapAsync(this);
like image 163
Deepak Goyal Avatar answered Sep 09 '25 22:09

Deepak Goyal