1

I want to get the latitude and longitude every n minutes and then use them in my app for setting the user in an area. The only problem is that I don't know how to get the location every -let's say- 2 minutes.

PS: I'm using both GPS and WiFi

Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56
Andreea Mateescu
  • 139
  • 1
  • 3
  • 12
  • Welcome to Stack Overflow! Can you please have a better title and more detailed information in the content with your effort to solve the problem? – Enamul Hassan Aug 21 '16 at 00:31

1 Answers1

0

just adjust it according to your need.

    Timer timer = new Timer ();
    TimerTask hourlyTask = new TimerTask () {
    @Override
    public void run () {
        // check if GPS enabled
        GPSTracker gpsTracker = new GPSTracker(this);
        if (gpsTracker.getIsGPSTrackingEnabled()){
            String stringLatitude = String.valueOf(gpsTracker.latitude);
            String stringLongitude = String.valueOf(gpsTracker.longitude);
            }
        }
    };

// schedule the task to RUN every hour
timer.schedule (hourlyTask, 0l, 1000*60*60);   // 1000*10*60 every 10 minut
Amit Bhandari
  • 3,014
  • 6
  • 15
  • 33