Reputation: 364
Android provides geolocation api for handling user location using gps,gsm or wifi. With this, one can determine the current location of user. My method is solely based on the inputs from the gps-receiver
Using Geolocation API, how can i determine for how long a user is on a particular geolocation ?
Upvotes: 0
Views: 191
Reputation: 3714
Try with a runnable like:
private Handler handler = new Handler();
public static final int timeElapsedCheckingDelay = 100; // in ms
private float timeElapsed = 0;
private Runnable timeElapsedChecker = new Runnable()
{
public void run()
{
if(gpsActual != gpsLast) //get the last position and check
{
//You can export wherever for example a toast
timeElapsed = 0;
gpsActual = gpsLast;
}
else
timeElapsed +=0.1;
handler.removeCallbacks(timeElapsedChecker); // remove the old callback
handler.postDelayed(timeElapsedChecker, timeElapsedCheckingDelay);
}
};
This is more or less pseudocode hope that it helps you :)
Upvotes: 1