While it's expected that LastLocation doesn't provide a location for the first time if it's unknown. I didn't expect to see the same issue with GetCurrentLocation
.
val mFusedLocationClient: FusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(mContext)
mFusedLocationClient.getCurrentLocation(LocationRequest.PRIORITY_HIGH_ACCURACY, object: CancellationToken() {
override fun onCanceledRequested(p0: OnTokenCanceledListener) = CancellationTokenSource().token
override fun isCancellationRequested() = false
}).addOnCompleteListener { it ->
if (it.isSuccessful) {
val location: Location = it.result
// Why can this be null if it was a success?
}
}
How can it.isSuccessful
be true and at the same time, showing the it.result
(location) as null?