Skip to content

Commit f9c52c7

Browse files
authored
chore: Remove KTX from basic map demo (googlemaps-samples#196)
1 parent 5ac76bb commit f9c52c7

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

ApiDemos/kotlin/app/build.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ dependencies {
4848
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4949
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
5050

51-
// Google Maps KTX extensions
52-
implementation 'com.google.maps.android:maps-ktx:1.4.0'
53-
54-
// Needed for coroutines
55-
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0'
56-
5751
// Below is used to run the easypermissions library to manage location permissions
5852
// EasyPermissions is needed to help us request for permission to access location
5953
implementation 'pub.devrel:easypermissions:3.0.0'

ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/BasicMapDemoActivity.kt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,40 @@ package com.example.kotlindemos
1818

1919
import android.os.Bundle
2020
import androidx.appcompat.app.AppCompatActivity
21-
import androidx.lifecycle.coroutineScope
2221
import com.google.android.gms.maps.CameraUpdateFactory
22+
import com.google.android.gms.maps.GoogleMap
23+
import com.google.android.gms.maps.OnMapReadyCallback
2324
import com.google.android.gms.maps.SupportMapFragment
2425
import com.google.android.gms.maps.model.LatLng
25-
import com.google.maps.android.ktx.MapsExperimentalFeature
26-
import com.google.maps.android.ktx.addMarker
27-
import com.google.maps.android.ktx.awaitMap
26+
import com.google.android.gms.maps.model.MarkerOptions
2827

2928
/**
3029
* This shows how to create a simple activity with a map and a marker on the map.
3130
*/
3231
class BasicMapDemoActivity :
33-
AppCompatActivity() {
32+
AppCompatActivity(),
33+
OnMapReadyCallback {
3434

3535
val SYDNEY = LatLng(-33.862, 151.21)
3636
val ZOOM_LEVEL = 13f
3737

38-
@MapsExperimentalFeature
3938
override fun onCreate(savedInstanceState: Bundle?) {
4039
super.onCreate(savedInstanceState)
4140
setContentView(R.layout.activity_basic_map_demo)
42-
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as? SupportMapFragment
41+
val mapFragment : SupportMapFragment? =
42+
supportFragmentManager.findFragmentById(R.id.map) as? SupportMapFragment
43+
mapFragment?.getMapAsync(this)
44+
}
4345

44-
lifecycle.coroutineScope.launchWhenCreated {
45-
val googleMap = mapFragment?.awaitMap() // Execution pauses here until we get the callback from the Maps SDK with a googleMap.
46-
// This is where we can add markers or lines, add listeners or move the camera.
47-
// In this case, we just move the camera to Sydney and add a marker in Sydney.
48-
with(googleMap) {
49-
this?.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, ZOOM_LEVEL))
50-
this?.addMarker {
51-
position(SYDNEY)
52-
}
53-
}
46+
/**
47+
* This is where we can add markers or lines, add listeners or move the camera. In this case,
48+
* we just move the camera to Sydney and add a marker in Sydney.
49+
*/
50+
override fun onMapReady(googleMap: GoogleMap?) {
51+
googleMap ?: return
52+
with(googleMap) {
53+
moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, ZOOM_LEVEL))
54+
addMarker(MarkerOptions().position(SYDNEY))
5455
}
5556
}
5657
}

0 commit comments

Comments
 (0)