Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LocationCallback not getting called

Tags:

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?

like image 624
TechieLover12 Avatar asked Jun 15 '18 06:06

TechieLover12


People also ask

What is LocationCallback in Android?

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) .

What is fused location provider client?

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.


1 Answers

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.

like image 75
Santiago Carrillo Avatar answered Sep 28 '22 01:09

Santiago Carrillo