2

I need to add a method to capture the latitude and longitude that I use to show it, I am only interested in obtaining the two values ​​when a button is pressed to show it and then I am no longer interested in moving. Thanks in advance. This form turned out to me but sometimes it returns to me null I don't know why?

LocationManager locationManager = (LocationManager)getSystemService(this.LOCATION_SERVICE);
Criteria criteria = new Criteria();

Location location = locationManager.getLastKnownLocation (locationManager.getBestProvider(criteria, false));

double latitudActual =  location.getLatitude();
double longitudActual = location.getLongitude();
Cyrille Con Morales
  • 918
  • 1
  • 6
  • 21

1 Answers1

0

You are using getlastknowLocation which might be null Try using location listener as stated here How do I get the current GPS location programmatically in Android?

Sadique Khan
  • 230
  • 3
  • 9