From f9c52c7673cceab89cbf450890e8d608dc9aed34 Mon Sep 17 00:00:00 2001 From: Sean Barbeau Date: Fri, 8 May 2020 18:28:54 -0400 Subject: [PATCH] chore: Remove KTX from basic map demo (#196) --- ApiDemos/kotlin/app/build.gradle | 6 ---- .../kotlindemos/BasicMapDemoActivity.kt | 35 ++++++++++--------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/ApiDemos/kotlin/app/build.gradle b/ApiDemos/kotlin/app/build.gradle index 2b14eaf3..120e578d 100644 --- a/ApiDemos/kotlin/app/build.gradle +++ b/ApiDemos/kotlin/app/build.gradle @@ -48,12 +48,6 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'com.android.support.constraint:constraint-layout:1.1.3' - // Google Maps KTX extensions - implementation 'com.google.maps.android:maps-ktx:1.4.0' - - // Needed for coroutines - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0' - // Below is used to run the easypermissions library to manage location permissions // EasyPermissions is needed to help us request for permission to access location implementation 'pub.devrel:easypermissions:3.0.0' 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 c57618e9..1d4ce6cd 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 @@ -18,39 +18,40 @@ package com.example.kotlindemos 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.maps.android.ktx.MapsExperimentalFeature -import com.google.maps.android.ktx.addMarker -import com.google.maps.android.ktx.awaitMap +import com.google.android.gms.maps.model.MarkerOptions /** * This shows how to create a simple activity with a map and a marker on the map. */ class BasicMapDemoActivity : - AppCompatActivity() { + AppCompatActivity(), + OnMapReadyCallback { val SYDNEY = LatLng(-33.862, 151.21) val ZOOM_LEVEL = 13f - @MapsExperimentalFeature override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_basic_map_demo) - val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as? SupportMapFragment + val mapFragment : SupportMapFragment? = + supportFragmentManager.findFragmentById(R.id.map) as? SupportMapFragment + mapFragment?.getMapAsync(this) + } - lifecycle.coroutineScope.launchWhenCreated { - 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) { - this?.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, ZOOM_LEVEL)) - this?.addMarker { - position(SYDNEY) - } - } + /** + * 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. + */ + override fun onMapReady(googleMap: GoogleMap?) { + googleMap ?: return + with(googleMap) { + moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, ZOOM_LEVEL)) + addMarker(MarkerOptions().position(SYDNEY)) } } }