Reputation: 5173
I've found many examples about implementing Maps in fragment by using library support.fragment but How do we do it with android.app.Fragment library.
Support.fragment
<fragment
android:id="@+id/mapFragment"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Implementation:
public class TrackFragment extends Fragment {
SupportMapFragment supportMapFragment =
(SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.mapFragment);
supportMapFragment.getMapAsync(googleMap -> {
googleMap.setOnMapLoadedCallback(() -> { /* */ }
}
}
This is when I import
import android.support.v4.app.Fragment;
if I import android.app.Fragment
how do I get Map async? How do I load map?
Upvotes: 3
Views: 278
Reputation: 6857
class="com.google.android.gms.maps.SupportMapFragment
shall be replaced by class="com.google.android.gms.maps.MapFragment"
and
SupportMapFragment supportMapFragment =
(SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.mapFragment);
will be by
MapFragment supportMapFragment =
(MapFragment) getChildFragmentManager().findFragmentById(R.id.mapFragment);
For more, read out MapFragment extends Fragment
Upvotes: 2