Reputation: 1677
I am getting location from NETWORK_PROVIDER as below :
if(manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
{
val locationManager = mContext.getSystemService(Context.LOCATION_SERVICE) as LocationManager
// Define a listener that responds to location updates
val locationListener = object : LocationListener {
override fun onLocationChanged(location: Location) {
// Called when a new location is found by the network location provider.
if (location != null) {
lastLocation = location
currentLatLng = LatLng(location.latitude, location.longitude)
if (currentLatLng != null &&
currentLatLng.latitude != null &&
currentLatLng.longitude != null
) {
sharedPreferenceManager?.setStringData(
Constant.PrefKey.userLatitude,
"" + currentLatLng.latitude
)
sharedPreferenceManager?.setStringData(
Constant.PrefKey.userLongitude,
"" + currentLatLng.longitude
)
getAddress(currentLatLng)
}
}else{
ToastUtil.displayLongDurationToast(mContext,"Could not get Location. Please turn on GPS and try again.")
getAndSaveCurrentLocation()
}
}
}
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0L, 0f,locationListener)
But, at the last line for the method requestLocationUpdates am getting the error as :
None of the following function can be called with the arguments supplied
What might be the issue ? I have already passed valid parameters.
EDIT: Getting error for the arguments at this line :
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0L, 0f,locationListener)
Upvotes: 0
Views: 886
Reputation: 8355
Most probably you are importing wrong LocationListener. You are probably using com.google.android.gms.location.LocationListener
but you need to import android.location.LocationListener
Check your import and change the import to correct LocationListener and the call should work.
Upvotes: 1