I am making a location request using FusedLocationProviderClient. I have kept a timer for 30 seconds to check if location is received within that timeframe. Code is below:
public void requestLocationUpdates() { initializeLocationRequest(); mFusedLocationProviderClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null); startTimer(); } private void initializeLocationRequest() { mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(mContext); mLocationRequest = new LocationRequest(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(5000); mLocationRequest.setFastestInterval(5000); mLocationCallback = new LocationCallback() { @Override public void onLocationResult(LocationResult locationResult) { synchronized (SilentCurrentLocationProvider.this) { super.onLocationResult(locationResult); Location location = locationResult.getLastLocation(); } }; } private void startTimer() { if (mTimeout < 1) { mTimeout = mDefaultTimeout; } mTimer = new Timer(); mTimer.schedule(new LocationTimer(), mTimeout * 1000); }
On few devices, location is not coming. On debugging further, I found that LocationRequest and LocationCallback are being created, but it's not coming inside onLocationResult() method.
Since this is part of a live product, it's hard to debug on every device. Even I tried restarting the phone but it doesn't work. The user tried on other applications like Ola and location was coming there.
Location Permissions have been given as well.
Can anyone tell me possible reasons for this issue?
public interface LocationCallback. A LocationCallback is used to run code after a Location has been fetched by com. parse. ParseGeoPoint#getCurrentLocationInBackground(long, android. location.Criteria) .
The fused location provider is a location API in Google Play services that intelligently combines different signals to provide the location information that your app needs.
You need to request only the following permission:
Manifest.permission.ACCESS_FINE_LOCATION
I had the same issue and I was requesting both permissions with:
Manifest.permission.ACCESS_COARSE_LOCATION
When I removed COARSE LOCATION I got the update almost immediately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With