Android Location Update After Every 5min If Vehicle Not Moving
Asked Answered
C

1

6

I have a situation like the following:

If car is stationary(not moving) than i want to call location update api after every 5min. If car is moving than i want to call location update api after every 2min.

or

If car keep moving 2000 meters distance than need to call location update api after every 5min.Actually how to check that location is same or not?

Collywobbles answered 25/11, 2016 at 8:55 Comment(0)
T
3

You can receive Information about location changes with the Location Update Callback. Read more about it in the android developer docs. Here is a basic example on how you can detect if the location changed:

public class MainActivity extends ActionBarActivity implements LocationListener {
    private Location mLastKnownLocation;
    ...
    @Override
    public void onLocationChanged(Location location) {          
            //location changed
            mLastKnownLocation = location
        }           
    }
}

Basically you just receive information about the current location if the location changed.

So in your case where you want to know every 5 min / 2 min if the location changed implement a timer, loop, etc. to check every 5 min / 2 min if you received a locationChangedEvent and the location changed or not

Tion answered 25/11, 2016 at 9:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.