GoogleApiClient.OnConnectionFailedListener is deprecated?



>我使用 GoogleApiClient.ConnectionCallbacks ,GoogleApiClient.OnConnectionFailedListener(已弃用(获取当前纬度和经度。 我们用什么来获取位置而不是GoogleApiClient?

这里的Java代码:

private fun createGoogleApiClient(): GoogleApiClient? {
return GoogleApiClient.Builder(mContext).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build()
}
override fun onConnected(p0: Bundle?) {
if (!checkPermissions()) {
requestPermissions()
} else {
val location = LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest) { location: Location? -> onLocationChanged(location) }

if (location == null) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest) { location: Location? ->
onLocationChanged(location)
}
} else {

}
}

}
override fun onLocationChanged(p0: Location?) {
if (p0 != null) {
mCurrentLocation = p0
}
}

GoogleAPIClient 很久以前就被弃用了。要获取用户的位置,您必须使用融合位置提供程序。通过下面的链接,你会知道如何使用它: -

https://www.vogella.com/tutorials/AndroidLocationAPI/article.html

相关内容

  • 没有找到相关文章

最新更新