diff --git a/samples/location/src/main/java/com/example/platform/location/currentLocation/CurrentLocationScreen.kt b/samples/location/src/main/java/com/example/platform/location/currentLocation/CurrentLocationScreen.kt index dbe6bf0a..842f5a79 100644 --- a/samples/location/src/main/java/com/example/platform/location/currentLocation/CurrentLocationScreen.kt +++ b/samples/location/src/main/java/com/example/platform/location/currentLocation/CurrentLocationScreen.kt @@ -115,6 +115,7 @@ fun CurrentLocationContent(usePreciseLocation: Boolean) { onClick = { //To get more accurate or fresher device location use this method scope.launch(Dispatchers.IO) { + val cancellationTokenSource = CancellationTokenSource() val priority = if (usePreciseLocation) { Priority.PRIORITY_HIGH_ACCURACY } else { @@ -122,8 +123,8 @@ fun CurrentLocationContent(usePreciseLocation: Boolean) { } val result = locationClient.getCurrentLocation( priority, - CancellationTokenSource().token, - ).await() + cancellationTokenSource.token, + ).await(cancellationTokenSource) result?.let { fetchedLocation -> locationInfo = "Current location is \n" + "lat : ${fetchedLocation.latitude}\n" +