diff --git a/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/BasicMapDemoActivity.kt b/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/BasicMapDemoActivity.kt index 0ff7159d..c57618e9 100644 --- a/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/BasicMapDemoActivity.kt +++ b/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/BasicMapDemoActivity.kt @@ -20,12 +20,10 @@ import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.coroutineScope import com.google.android.gms.maps.CameraUpdateFactory -import com.google.android.gms.maps.GoogleMap -import com.google.android.gms.maps.OnMapReadyCallback import com.google.android.gms.maps.SupportMapFragment import com.google.android.gms.maps.model.LatLng -import com.google.android.gms.maps.model.MarkerOptions import com.google.maps.android.ktx.MapsExperimentalFeature +import com.google.maps.android.ktx.addMarker import com.google.maps.android.ktx.awaitMap /** @@ -44,13 +42,14 @@ class BasicMapDemoActivity : val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as? SupportMapFragment lifecycle.coroutineScope.launchWhenCreated { - check(mapFragment != null) - val googleMap = mapFragment.awaitMap() // Execution pauses here until we get the callback from the Maps SDK with a googleMap. + val googleMap = mapFragment?.awaitMap() // Execution pauses here until we get the callback from the Maps SDK with a googleMap. // This is where we can add markers or lines, add listeners or move the camera. // In this case, we just move the camera to Sydney and add a marker in Sydney. with(googleMap) { - moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, ZOOM_LEVEL)) - addMarker(MarkerOptions().position(SYDNEY)) + this?.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, ZOOM_LEVEL)) + this?.addMarker { + position(SYDNEY) + } } } }