Skip to content
This repository was archived by the owner on Dec 16, 2023. It is now read-only.

Commit 3c8d882

Browse files
committed
Fix crash on isMyLocationEnabled
Using `googleMap.isMyLocationEnabled` before the user has granted location permission results in a crash
1 parent 22f05c0 commit 3c8d882

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

app/src/main/java/com/marknkamau/justjava/ui/addAddress/AddAddressActivity.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ class AddAddressActivity : AppCompatActivity(), OnMapReadyCallback {
8383

8484
val nrb = LatLng(-1.286481, 36.817297)
8585
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(nrb, 14f))
86-
googleMap.isMyLocationEnabled = true
87-
googleMap.uiSettings.isMyLocationButtonEnabled = true
8886

8987
googleMap.setOnCameraIdleListener {
9088
target = googleMap.cameraPosition.target
@@ -93,6 +91,8 @@ class AddAddressActivity : AppCompatActivity(), OnMapReadyCallback {
9391

9492
if (hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
9593
getLastLocation()
94+
googleMap.isMyLocationEnabled = true
95+
googleMap.uiSettings.isMyLocationButtonEnabled = true
9696
} else {
9797
ActivityCompat.requestPermissions(
9898
this,
@@ -106,6 +106,8 @@ class AddAddressActivity : AppCompatActivity(), OnMapReadyCallback {
106106
if (requestCode == PERMISSIONS_REQUEST) {
107107
if (grantResults.permissionsGranted()) {
108108
getLastLocation()
109+
googleMap.isMyLocationEnabled = true
110+
googleMap.uiSettings.isMyLocationButtonEnabled = true
109111
}
110112
}
111113
}

0 commit comments

Comments
 (0)