GoogleApiClient.OnConnectionFailedListener已弃用?

问题描述 投票:0回答:1

我使用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
    }

}
android google-maps google-api-client
1个回答
0
投票

GoogleAPIClient很久不推荐使用。为了获得用户的位置,您必须使用融合的位置提供程序。通过下面的链接,您将了解如何使用它:-

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

© www.soinside.com 2019 - 2024. All rights reserved.