0

I want to show a marker on my google map in my fragment. I can load the google map without problems but when i run mapFragment.getMapAsync(this), the app crashes and I don't know why. Any tips?

this is the code:

public class ISSLocation extends Fragment implements OnMapReadyCallback {    

    View v    
    GoogleMap mapAPI;
    SupportMapFragment mapFragment;
    private FragmentActivity myContext;


    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        v = inflater.inflate(R.layout.activity_iss, container, false);

        FragmentManager fragManager = myContext.getSupportFragmentManager();

        mapFragment = (SupportMapFragment) fragManager.findFragmentById(R.id.mapAPI);
        mapFragment.getMapAsync(this);

        return v;
    }

 @Override
    public void onAttach(Activity activity) {
        myContext=(FragmentActivity) activity;
        super.onAttach(activity);
    }

 @Override
    public void onMapReady(GoogleMap googleMap) {
        mapAPI = googleMap;

        LatLng location = new LatLng(19.389137, 76.031094);
        mapAPI.addMarker(new MarkerOptions().position(location).title("Location"));
        mapAPI.moveCamera(CameraUpdateFactory.newLatLng(location));         
    }
}

this is the layout xml code:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:id="@+id/mapAPI"
        android:name="com.google.android.gms.maps.SupportMapFragment">

    </fragment>

</LinearLayout>

stacktrace: stacktrace

0 Answers0