androidandroid-fusedlocationfusedlocationproviderclient

Cannot resolve method 'getCurrentLocation' in 'FusedLocationProviderClient'


I am trying to use FusedLocationProviderClient.getCurrentLocation().

It's supposed to be available according to the documentation here.

But in Android Studio, I am getting the error

Cannot resolve method 'getCurrentLocation' in 'FusedLocationProviderClient'

I know the recommended approach is to implement requestLocationUpdates(), but that's not what I am after here.


Solution

  • You have to update to at least version 17.1.0 of the Google Play Location Services api. Include this line in your build.gradle (app):

    implementation "com.google.android.gms:play-services-location:17.1.0"