Geolocation - Get location of android device automatically

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I m working on an android app and i need to know the location of android device. All the methods I tried need GPS to be enabled. If it is not enabled, we can ask the user to turn it on by opening settings intent.

Is there any way to enable it via code, without even letting the user know.. and turn it off when the app has finished its job?

The app I m working on will keep record of location of device. It will run in background and will note location every 15mins. To keep GPS enabled all the time will consume a lot of power. So i want to turn it on when i need and turn it off when i m done, without asking the user.

Answers

For exact location, you need GPS to be enabled. But you can use NETWORK_PROVIDER, and get the latitude and longitude. This does not require user intervention. But, of course, its an approximate location but good enough to do location based searches.

lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
            locationListener);

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/15464094/get-location-of-android-device-automatically

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils