Android location update after every 5 minutes if the vehicle is not moving

I have the following situation:

If the car is stationary (does not move), I want to trigger an update of the api location every 5 minutes. If the car is moving, I want to trigger an api location update every 2 minutes.

or

If the car continues to move a distance of 2000 meters, what should be called updating the location api every 5 minutes. Usually, how to check that the location is the same or not?

+5
source share
1 answer

Location changes can be obtained using the Location Update Callback . Read more about this in the Android developer documentation . Here is a basic example of how you can determine if a location has changed:

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

Basically you just get the current location information if the location is changed .

So, in your case, when you want to know every 5 minutes / 2 min, if the change of location implements a timer, cycle, etc., to check every 5 min / 2 min if you got locationChangedEvent and the place has changed or not

+3
source

Source: https://habr.com/ru/post/1260332/


All Articles