Reputation: 123
I cannot fetch the location using LocationManager.GPS_PROVIDER
. But it is working with LocationManager.NETWORK_PROVIDER
.
val locationManager=getSystemService(Context.LOCATION_SERVICE) as LocationManager
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,500, 100F,listener)//It's working if i use NETWORK_PROVIDER
val listener=object :LocationListener {
override fun onLocationChanged(location: Location?) {
latitude = location!!.latitude.toString()
longitude = location!!.longitude.toString()
Log.d("location", "$latitude $longitude")
}
override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {
}
override fun onProviderEnabled(provider: String?) {
}
override fun onProviderDisabled(provider: String?) {
}
}
Upvotes: 0
Views: 233
Reputation: 36
Two Solutions:
1. Maybe your GPS location is switched off in your mobile device. So try to switch it ON and check location.
2. Try to implement Fused location provider which is provided by Google Play Services API as it improves performance, saves battery life and provides more accurate location
Upvotes: 2