Skip to content

Instantly share code, notes, and snippets.

@alizahid
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alizahid/f720c563b1508a1e871b to your computer and use it in GitHub Desktop.
Save alizahid/f720c563b1508a1e871b to your computer and use it in GitHub Desktop.
Google Play location API
package com.example;
import android.content.Context;
import android.os.Bundle;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;
public class Location implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private GoogleApiClient client;
public Location(Context context) {
client = new GoogleApiClient.Builder(context).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build();
client.connect();
}
@Override
public void onConnected(Bundle bundle) {
android.location.Location location = LocationServices.FusedLocationApi.getLastLocation(client);
// do what you want with location
client.disconnect();
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
@Override
public void onConnectionSuspended(int i) {
client.connect();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment