I am getting the error None of the following functions can be called with the arguments supplied
when trying to call requestLocationUpdates()
using Kotlin. I've gotten this issue before in other places and have been able to fix it, but I'm not able to in this case. I'm relatively new to the language and don't fully understand the issue here.
The issue is with the LocationListener that is passed in. It is expecting a LocationListener!
, but apparently that isn't what it's getting.
Here is the snippet of code:
private var locationManager: LocationManager? = null
private var latitude: Double? = null
private var longitude: Double? = null
//private val locationListener: com.google.android.gms.location.LocationListener
private val locationListener: com.google.android.gms.location.LocationListener = object : com.google.android.gms.location.LocationListener {
override fun onLocationChanged(location: Location) {
latitude = location.latitude
longitude = location.longitude
}
}
init {
// Initialize Places.
Places.initialize(activity, BuildConfig.googlePlacesAPI_KEY)
Places.createClient(activity)
locationManager = activity.getSystemService(Context.LOCATION_SERVICE) as LocationManager?
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 50f, locationListener)
if (locationManager!!.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
getLocation(activity)
}
}