Last active
August 29, 2015 14:11
-
-
Save LordRaydenMK/2fc4812fe24937ccc693 to your computer and use it in GitHub Desktop.
Requesting location updates using the LocationClient from Google Play Services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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