Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Location Update After Every 5min If Vehicle Not Moving

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?

like image 902
Lokesh Desai Avatar asked Nov 25 '16 08:11

Lokesh Desai


1 Answers

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

like image 159
IIIIIIIIIIIIIIIIIIIIII Avatar answered Nov 15 '22 03:11

IIIIIIIIIIIIIIIIIIIIII