Geolocation - other way to get current location in android

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

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();

Answers

sure you could use the google play services location API: http://developer.android.com/google/play-services/location.html 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: http://stackoverflow.com/questions/10689372/android-getlastknownlocation-returns-null http://stackoverflow.com/questions/10689372/android-getlastknownlocation-returns-null

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/22594281/other-way-to-get-current-location-in-android

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils