0

when i set time intervel in LocationRequest then location getting perfectly using this code

private static final long INTERVAL = 500 * 1;
private static final long FASTEST_INTERVAL = 500 * 1;
private static final int SMALLEST_DISPLACEMENT = 5;

protected void createLocationRequest() {
    LocationRequest mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(INTERVAL);
    mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
    mLocationRequest.setSmallestDisplacement(SMALLEST_DISPLACEMENT);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}

but when i remove these line then onLocationChanged not working. is it neccessary to set time intervel in LocationRequest?

 mLocationRequest.setInterval(INTERVAL);
 mLocationRequest.setFastestInterval(FASTEST_INTERVAL);

i want to get location according to displacement not according to time intervel.

Hitesh Gehlot
  • 1,307
  • 1
  • 15
  • 30
  • as far as I can rememeber, if you don´t set the interval, it doesn´t update with interval (or after long time, something like 60 minutes), only if location is changed. – Opiatefuchs May 11 '17 at 13:19
  • if you not set interval you will never get location. i am continuously driving but my location only update after time interval. onLocationChanged depends on time intervel not on displacement. – Hitesh Gehlot May 11 '17 at 13:55

1 Answers1

0

It also surprised me, please someone correct me if i'm interpreting wrongly.

From the LocationRequest source code;

private long mInterval = 60 * 60 * 1000;   // 60 minutes
private long mFastestInterval = (long)(mInterval / FASTEST_INTERVAL_FACTOR);  // 10 minutes

If you dont set setIntervaland setFastestInterval, then they keep their default values.

So, when you set only mLocationRequest.setSmallestDisplacement(...);

Then fused provider considers values like

Interval : 60 minutes, Fastest Interval : 10 minutes, SmallestDisplacement : 5m

As a result, it seeming like "not working"

Community
  • 1
  • 1
blackkara
  • 4,900
  • 4
  • 28
  • 58
  • yes its not working. you will get new location after 10 min. Why we depends on time interval. why new location not getting after 5m displacement – Hitesh Gehlot May 11 '17 at 13:53
  • I mean't it's actually working. Due to interval values have default, you didn't see a possible `onLocationChanged` call (maybe you didn't wait at least 10 minutes or more) – blackkara May 11 '17 at 13:58