0

i am working in get gps location using tower id and gps in this i can get the current location and displaying it in toast i have to dislpay it automatically for every five minutes and also to display it in maps on android device can anybody help me. my code is

public void onClick(View arg0) {        
                // create class object
                gps = new GPSTracker(AndroidGPSTrackingActivity.this);

                // check if GPS enabled     
                if(gps.canGetLocation()){

                    double latitude = gps.getLatitude();
                    double longitude = gps.getLongitude();

                    // \n is for new line
                    Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();    
                }else{
                    Toast.makeText(getApplicationContext(),"cant get location", 1000 ).show(); 
                    // GPS or Network is not enabled
                    // Ask user to enable GPS/network in settings
                    gps.showSettingsAlert();
                }

            }

2 Answers2

0

Look at LocationManager.requestLocationUpdates. It will automatically update you when the location provider updates. You can set a maximum frequency for it to 5 minutes in that API.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
0
   thread1=new Thread(new Runnable() {

            public void run() {
                // TODO Auto-generated method stub
                while (true) {
                    try {
                        Thread.sleep(1000*60*5);
                        mHandler.post(new Runnable() {


                            public void run() {
                                // TODO Auto-generated method stub
                                // Write your code here to update the UI.
                       });
                    } catch (Exception e) {
                        // TODO: handle exception
                    }
                }
            }
        });
Jai Kumar
  • 920
  • 1
  • 7
  • 14
  • thanks for your reply can you show me how to run this service in background for every fivebminutes –  Apr 17 '13 at 06:33