如何解决在我的代码中,我可以在融合的位置提供者超时中找到LocationProviderClientClient.requestLocationUpdate
val fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this)
fusedLocationProviderClient.lastLocation.addOnSuccessListener(this) { location ->
if(location != null) {
presenter.getNearbyCollection(location.latitude.toString(),location.longitude.toString())
}
else {
showProgress("")
val locationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult) {
hideProgress()
presenter.getNearbyCollection(locationResult.lastLocation.latitude.toString(),locationResult.lastLocation.longitude.toString())
fusedLocationProviderClient.removeLocationUpdates(this)
}
}
val locationResult = LocationRequest()
locationResult.maxWaitTime = 60*1000
locationResult.interval = 30*1000
locationResult.fastestInterval = 10*1000
fusedLocationProviderClient.requestLocationUpdates(locationResult,locationCallback,null)
}
}
fusedLocationProviderClient.lastLocation.addOnFailureListener(this){
hideProgress()
showMessage(SnackBarUtil.ERROR,"Not able to fetch")
}
fusedLocationProviderClient.lastLocation.addOnCanceledListener(this){
hideProgress()
showMessage(SnackBarUtil.ERROR,"Canceled")
}
在我的代码中,我可以超时。我将maxWaitTime设置为1秒。但1秒钟后,它仍在加载。还是有任何回调方法可以使超时
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。