mirror of
https://github.com/googlemaps/android-samples.git
synced 2025-12-08 18:02:20 +00:00
chore: Remove KTX from basic map demo (#196)
This commit is contained in:
parent
5ac76bb18b
commit
f9c52c7673
@ -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'
|
||||
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user