• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to get Location object in LocationListener class?

sneaky666

Lurker
In this code, i made a method called handle_timer, but how do I get the 'Location' argument in it, like from here "public void onLocationChanged(Location loc)" ? The code has some errors in it currently...

Can anyone help?
Thanks


Code:
    public class MyLocationListener implements LocationListener {
        
        public void send_gps_via_sms(Location loc) {
            loc.getLatitude();
            loc.getLongitude();
            String Text = "My current location is: " + "Latitude = " + loc.getLatitude() + " Longitude = " + loc.getLongitude();
            Toast.makeText(getApplicationContext(), "hi", Toast.LENGTH_SHORT).show();
            sendSMS("416_______", Text); // currently this will spam you with texts, I need to find way to put a 1 min frequency
        }
        
        public void handle_timer(Location loc) {
            send_gps_via_sms(loc);
            CountDownTimer my_timer = new CountDownTimer(30000, 1000) {
                 public void onTick(long millisUntilFinished) {
                     String time_left = "seconds remaining: " + millisUntilFinished / 1000;
                     Toast.makeText(getApplicationContext(), time_left, Toast.LENGTH_SHORT).show();
                     //mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
                 }
            
                 public void onFinish() {
                     Toast.makeText(getApplicationContext(), "Done!", Toast.LENGTH_SHORT).show();
                     handle_timer(loc);
                 }
             }.start();
        }
        
        public void onLocationChanged(Location loc) {
        }
        
        public void onProviderDisabled(String provider) {
            Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show();
        }

        public void onProviderEnabled(String provider) {
            Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();
        }
        
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    }
 
Back
Top Bottom