public
class
MainActivity
extends
Activity
implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private
GoogleApiClient mGoogleClient;
private
TextView _text;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
mGoogleClient =
new
GoogleApiClient.Builder(
this
,
this
,
this
).addApi(
LocationServices.API).build();
_text = (TextView) findViewById(R.id.textView1);
Button btn1 = (Button) findViewById(R.id.button1);
btn1.setOnClickListener(
new
View.OnClickListener() {
@Override
public
void
onClick(View v) {
Location location = LocationServices.FusedLocationApi
.getLastLocation(mGoogleClient);
}
});
}
@Override
protected
void
onStart() {
super
.onStart();
mGoogleClient.connect();
}
@Override
protected
void
onStop() {
mGoogleClient.disconnect();
super
.onStop();
}
@Override
public
void
onConnected(Bundle connectionHint) {
}
@Override
public
void
onConnectionSuspended(
int
cause) {
}
@Override
public
void
onConnectionFailed(ConnectionResult connectionResult) {
if
(connectionResult.hasResolution()) {
try
{
connectionResult.startResolutionForResult(
this
,
0
);
}
catch
(IntentSender.SendIntentException e) {
}
}
else
{
}
}
}