From 581ae289a6cedd72b00a74c63cb28a21534b62ca Mon Sep 17 00:00:00 2001 From: Sean Barbeau Date: Thu, 7 May 2020 12:23:54 -0400 Subject: [PATCH] chore: Update basic map demo (#193) Based on additional comments in https://github.com/googlemaps/android-samples/pull/188: * Use KTX for addMarker() * Allow optional for GoogleMap --- .../com/example/kotlindemos/BasicMapDemoActivity.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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) + } } } }