Skip to content

Instantly share code, notes, and snippets.

@LordRaydenMK
Last active August 29, 2015 14:11
Show Gist options
  • Save LordRaydenMK/2fc4812fe24937ccc693 to your computer and use it in GitHub Desktop.
Save LordRaydenMK/2fc4812fe24937ccc693 to your computer and use it in GitHub Desktop.
Requesting location updates using the LocationClient from Google Play Services
public class MainActivity extends Activity implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener, LocationListener {
private LocationRequest mLocationRequest;
private LocationClient mLocationClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLocationRequest = LocationRequest.create();
mLocationClient = new LocationClient(this, this, this);
}
@Override
protected void onStart() {
super.onStart();
mLocationClient.connect();
}
@Override
protected void onStop() {
super.onStop();
if (mLocationClient.isConnected()) {
mLocationClient.removeLocationUpdates(this);
}
mLocationClient.disconnect();
}
@Override
public void onConnected(Bundle bundle) {
mLocationClient.requestLocationUpdates(mLocationRequest, this);
}
@Override
public void onDisconnected() {
}
@Override
public void onLocationChanged(Location location) {
//Here we have our location update
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment