具有服务Android Kotlin的FusedLocationProviderClient [英] FusedLocationProviderClient With Service Android Kotlin
本文介绍了具有服务Android Kotlin的FusedLocationProviderClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Fused Api进行位置更新.我正在将Fused Api与Activity一起使用正常.但是,当我在服务类中使用它时,它会显示这是我的服务类代码.发生错误的地方
解决方案
Class Task
(This is my Service class code . Where error occurring
解决方案
Class Task
(https://developers.google.com/android/reference/com/google/android/gms/tasks/Task) have three overloads of method addOnCompleteListener
:
addOnCompleteListener(OnCompleteListener<TResult> listener)
addOnCompleteListener(Activity activity, OnCompleteListener<TResult> listener)
addOnCompleteListener(Executor executor, OnCompleteListener<TResult> listener)
Your Service
is neither Activity
, nor Executor
. So the two latter overloads are not applicable for you. Just drop the first parameter and use it like that:
mFusedLocationClient!!.lastLocation.addOnCompleteListener { task ->
//do something
}
这篇关于具有服务Android Kotlin的FusedLocationProviderClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文