-1

I have used manager.requestLocationUpdates("gps", 1800000, 1, new LocationDetector()); method of LocationManager manager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); class for getting update when either location change (device's location) is at least 1 meter (almost 40 inches), OR at least 30 minutes has passed. But the update is not being received when I change device's location by 1 meter (or even more). So what can be the problem? Please tell.

Code:

public class LocationDetector implements LocationListener {
    @Override
    public void onLocationChanged(Location location) {
        Log.d("GPS: ",location.getLatitude()+", "+location.getLongitude());
    }
Sajal Ali
  • 427
  • 1
  • 10
  • 21

1 Answers1

0

It's not OR, it's AND.

To get a location update with those parameters the distance needs to change at least 1 meter AND 30 minutes needs to have passed since the previous update.

Android documentation:

The minDistance parameter can also be used to control the frequency of location updates. If it is greater than 0 then the location provider will only send your application an update when the location has changed by at least minDistance meters, AND at least minTime milliseconds have passed.

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
  • but the update is being received after 30 minutes without change in location of device. – Sajal Ali May 08 '16 at 08:19
  • Like said [in here](http://stackoverflow.com/questions/37094660/requestlocationupdates-method-is-giving-updates-without-change-in-location-a/37097663#37097663) there probably is a change in the location as GPS coordinates can fluctuate even for a device lying perfectly still. – Markus Kauppinen May 08 '16 at 08:24