Code example for LocationClient

Methods: getLastLocationrequestLocationUpdates

0
 
    @Override 
    public void onConnected(Bundle bundle) {
 
 
        Location location = mLocationClient.getLastLocation();
        if (location != null) {
            mBus.post(new LocationChangedEvent(new LatLng(location.getLatitude(), location.getLongitude()), "You are here!", true));
        } 
 
        startLocationUpdates(); 
 
    } 
 
    @Subscribe 
    public void OnMapClicked(MapClickedEvent event){
        stopLocationUpdates(); 
    } 
 
    @Override 
    public void onDisconnected() { 
        //Do something on disconnect 
    } 
 
    @Override 
    public void onConnectionFailed(ConnectionResult connectionResult) {
        //Do something if the connection to Google Play Services fails 
    } 
 
    @Override 
    public void onLocationChanged(Location location) {
        mBus.post(new LocationChangedEvent(new LatLng(location.getLatitude(), location.getLongitude()), "You are here!", true));
    } 
 
    private void startLocationUpdates() { 
        Log.d("FindMe", "Starting location updates...");
        mLocationClient.requestLocationUpdates(mLocationRequest, this);
    } 
 
    private void stopLocationUpdates() { 
        Log.d("FindMe", "Stopping location updates");
        mLocationClient.removeLocationUpdates(this);