public class LocationService
extends Service
implements com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks, com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener
Modifier and Type | Class and Description |
---|---|
private class |
LocationService.LocationListener
Calls sendLocationToServer when the location changes
|
Modifier and Type | Field and Description |
---|---|
static long |
FASTEST_UPDATE_INTERVAL |
private static int |
LOCATION_INTERVAL |
private LocationService.LocationListener |
locationListener |
private com.google.android.gms.common.api.GoogleApiClient |
mGoogleApiClient |
private com.google.android.gms.location.LocationRequest |
mLocationRequest |
private static java.lang.String |
TAG |
Constructor and Description |
---|
LocationService() |
Modifier and Type | Method and Description |
---|---|
IBinder |
onBind(Intent arg0) |
void |
onConnected(Bundle bundle)
Since the Google API Client is connected, the device can start the location services
|
void |
onConnectionFailed(com.google.android.gms.common.ConnectionResult arg0) |
void |
onConnectionSuspended(int i) |
void |
onCreate()
Tries to connect to the Google API client
|
void |
onDestroy() |
int |
onStartCommand(Intent intent,
int flags,
int startId) |
private void |
sendLocationToServer(Location lastLocation)
Sends a PATCH request to the server with the location of the user
|
private void |
startLocationUpdates()
Starts up the location services
|
void |
stopLocationUpdates()
Stops the location services
|
private static final java.lang.String TAG
private static final int LOCATION_INTERVAL
public static final long FASTEST_UPDATE_INTERVAL
private com.google.android.gms.common.api.GoogleApiClient mGoogleApiClient
private com.google.android.gms.location.LocationRequest mLocationRequest
private LocationService.LocationListener locationListener
public void onConnected(Bundle bundle)
onConnected
in interface com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks
startLocationUpdates()
private void startLocationUpdates()
public void onConnectionSuspended(int i)
onConnectionSuspended
in interface com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks
public void onConnectionFailed(@NonNull com.google.android.gms.common.ConnectionResult arg0)
onConnectionFailed
in interface com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener
public IBinder onBind(Intent arg0)
public int onStartCommand(Intent intent, int flags, int startId)
public void onCreate()
onConnected(Bundle)
public void onDestroy()
public void stopLocationUpdates()
private void sendLocationToServer(Location lastLocation)
lastLocation
- the location