1,234
edits
Changes
no edit summary
= Location APIs =
There are two: [http://developer.android.com/reference/android/location/package-summary.html android.location] and the [https://developer.android.com/training/location/index.html Google Play Services API]. They both work and Google encourages you to use their proprietary APIs, which may but may not be in fact in your interest. To save time we We'll use the android.location API: it requires very little setup and there's a very nice tutorial available [http://www.vogella.com/tutorials/AndroidLocationAPI/article.html from Vogella]. == Setup to use location == * If you forget to ask for permissions to read the location, you'll only look at just get a null provider without any error or warning messages. So add the Google Play APIs hereappropriate permission to your manifest. == Getting your location == * You don't read the location directly from the GPS, they are better documentedyou get it from the Location Manager - a system service. You'll want to keep the reference to this service around:<source lang="java">locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);</source>* We'll need to keep the name of the provider we want to use around.This code asks for the best provider given [http://developer.android.com/reference/android/location/Criteria.html the criteria] and the permissions in our manifest:<source lang="java">Criteria criteria = new Criteria();provider = locationManager.getBestProvider(criteria, false);</source>*
== Setup to use Google Play Services ==