Created
May 20, 2021 07:23
-
-
Save DevPicon/494b6f3643da584bce6658a8cf1a47be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun addDestinationOnMap( | |
googleMap: GoogleMap, | |
shopperLocation: Location, | |
destinationLocation: LatLng | |
) { | |
lifecycle.coroutineScope.launchWhenCreated { | |
googleMap.clear() | |
val latLngBounds = LatLngBounds.Builder() | |
.include(LatLng(shopperLocation.latitude, shopperLocation.longitude)) | |
.build() | |
val originCameraPosition = buildCameraPosition(latLngBounds) | |
val originCameraUpdate = CameraUpdateFactory.newCameraPosition(originCameraPosition) | |
val destinationLatLngBounds = LatLngBounds.Builder() | |
.include(LatLng(destinationLocation.latitude, destinationLocation.longitude)) | |
.build() | |
val destinationCameraPosition = buildCameraPosition(destinationLatLngBounds) | |
val destinationCameraUpdate = | |
CameraUpdateFactory.newCameraPosition(destinationCameraPosition) | |
googleMap.moveCamera(originCameraUpdate) | |
googleMap.awaitAnimateCamera(destinationCameraUpdate, durationMs = 1500) | |
delay(500) | |
googleMap.addMarker { | |
position(destinationLocation) | |
title("Marker in destination") | |
} | |
googleMap.stopAnimation() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// KTX for the Maps SDK for Android library | |
implementation 'com.google.maps.android:maps-ktx:3.0.1' | |
// KTX for the Maps SDK for Android Utility Library | |
implementation 'com.google.maps.android:maps-utils-ktx:3.0.1' | |
implementation "com.google.android.gms:play-services-maps:$google_gms_maps_version" | |
implementation 'com.google.maps.android:android-maps-utils:2.0.3' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment