mirror of
https://github.com/googlemaps/android-samples.git
synced 2025-12-08 18:02:20 +00:00
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
This commit is contained in:
parent
5e6540cc6b
commit
581ae289a6
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user