0

the code below gives a NullPointerException is there any other way of getting current location in Android application

LocationListener locationListener = new LocationListener() 
{
    public void onLocationChanged(Location location) {}

    public void onStatusChanged(String provider, int status, Bundle extras) {}

    public void onProviderEnabled(String provider) {}

    public void onProviderDisabled(String provider) {}

};

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE)

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);

Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);


double latitude = location.getLatitude(); //NullPointerException
double longitude = location.getLongitude();
Cœur
  • 37,241
  • 25
  • 195
  • 267
Udit Bhardwaj
  • 1,761
  • 1
  • 19
  • 29

1 Answers1

0

sure you could use the google play services location API: http://developer.android.com/google/play-services/location.html

but maybe you should look into your problem first... see this question for your null problem: android getlastknownlocation returns null

Community
  • 1
  • 1
yekretsaM
  • 421
  • 1
  • 4
  • 10