How can I add GPS service to my application?

Prev Next

The Blade pulls GPS location data from a linked companion device.

As such, you will need to define a location listener:

private final LocationListener mLocationListener = new LocationListener() {
	@Override
	public void onLocationChanged(final Location location) {
        	//your code here
    	}
};

Then utilize the LocationManager API to register for updates:

mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, LOCATION_REFRESH_TIME, LOCATION_REFRESH_DISTANCE, mLocationListener);

And finally, add the permissions to access the data by adding one of the following to your manifest:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

or

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>