我使用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
}
}
答案 0 :(得分:0)
不建议使用GoogleAPIClient。为了获得用户的位置,您必须使用融合的位置提供程序。通过下面的链接,您将了解如何使用它:-
https://www.vogella.com/tutorials/AndroidLocationAPI/article.html