I am using GoogleMap
in android app using Android Studio
. It was working fine and don\'t know why suddenly it stopped working. minSdkVersion is 15
After adding permission in manifest, It solved my issue. Check below code :
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="24" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="24" />
getChildFragmentManager
is used in Nested Fragments. The fragment you've used is not a child of another fragment. Use getSupportFragmentManager
or getFragmentManager
for fragment transactions.
Take a look at this question for more information.
In addition, I would like to mention that You're integrating an old Maps API. Try the latest one https://developers.google.com/maps/documentation/android-api/map
If it crashes second time, you need to destroy it.
public void onDestroy() {
super.onDestroy();
getFragmentManager().beginTransaction().remove(mapfragmentnamehere).commit();
}
public void onMapReady(GoogleMap googleMap) {
setUpMap(googleMap);
}
Please use getMapAsync.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this)
In your onCreate
add:
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
In XML add context
:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.___yourPackageName______"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/mapFragment"
class="com.google.android.gms.maps.SupportMapFragment"
tools:context="com.___yourPackageName______"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>