Skip to content

Instantly share code, notes, and snippets.

@LordRaydenMK
Last active September 11, 2017 11:46
Show Gist options
  • Save LordRaydenMK/1439f1a01e88f83bf75c to your computer and use it in GitHub Desktop.
Save LordRaydenMK/1439f1a01e88f83bf75c to your computer and use it in GitHub Desktop.
Using the FusedLocationProviderApi to request location updates
public class MainActivity extends Activity implements LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private LocationRequest mLocationRequest;
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLocationRequest = LocationRequest.create();
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
}
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
super.onStop();
if(mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
@Override
public void onConnected(Bundle bundle) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onLocationChanged(Location location) {
//u
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment