0

I want to find the GPS coordinates of current location on click of a button using GPS_PROVIDER. After clicking on button in place 'A' I will close the app and go to the place B and click the button again to get the B coordinates. How can I do this ? Do I have to define a listener that responds to location updates?

RandomMooCow
  • 734
  • 9
  • 23
user1129655
  • 55
  • 1
  • 6
  • possible duplicate of [How do I get the current GPS location programmatically in Android?](http://stackoverflow.com/questions/1513485/how-do-i-get-the-current-gps-location-programmatically-in-android) – JasonMArcher Sep 29 '14 at 18:16

1 Answers1

0

You can use following code for fetching gps data,

package com.gpsexample.location;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;

public class LocListener implements LocationListener
{
    private static double lat =0.0;
    private static double lon = 0.0;
    private static double alt = 0.0; 
    private static double speed = 0.0;

    public static double getLat()
    {
        return lat;
    }

    public static double getLon() 
    {
        return lon;
    }

    public static double getAlt()
    {
        return alt;
    }

    public static double getSpeed()
    {
        return speed;
    }

    @Override
    public void onLocationChanged(Location location) 
    {
        lat = location.getLatitude();
        lon = location.getLongitude();
        alt = location.getAltitude();
        speed = location.getSpeed(); 
    }

    @Override
    public void onProviderDisabled(String provider) {}
    @Override
    public void onProviderEnabled(String provider) {}
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {}
}
Lucifer
  • 29,392
  • 25
  • 90
  • 143