This project aims to provide a simple way to access Location based services.
Google Play Services provides Location Services, which is a handy way of accesing location information on Android devices. However there is a bunch of checks, methods, callbacks and whatnots that are particulaty annoying to implement everytime. This is just a simple Activity wrapping around all that and exposing the data through a couple abstract methods.
Add the following permissions in order to be able to access Location Services
<manifest>
...
<!-- PERMISSIONS -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- /PERMISSIONS -->
...
<application android:name="MyApplication">
...
</application>
</manifest>
Your build.gradle file will need the following dependency
compile 'com.google.android.gms:play-services:3.2.+'
If you don't use yet the new build system based on gradle, notice that you need the Play Services library.
Copy LocationActivity to your project and let your activity extend it. Then implement
void onNewLocationFix()
LocationRequest getLocationRequest()
onNewLocationFix()
will be called everytime there is a new location fix available.
getLocationRequest()
provides the criteria which the location fixes will follow, as documented here**.
void startLocationUpdates()
void stopLocationUpdates()
Location getLastFix()
This three are self-explanatory. Start/Stop receiving updates and access the latest fix available.
There is an sample implementation you can check-out and try.
If you try to import it into Android Studio it will probably complain about not finding the Android SDK. If that's the case just provide the location in a local.properties file in the root folder of the project.
No Geofencing (shouldn't be hard to add though).
No PendingIntents. Just the activity extending LocationActivity will get notified of new fixes.
Needless to say LocationActivity has not been tested thoroughly. It's just a mini-help. If you find any problems don't hesitate opening an issue.