Android LocationClient - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android LocationClient class.

This code example shows how to use the following methods:disconnect, isConnected, removeLocationUpdates
    } 
 
    @Override 
    protected void onStop() { 
 
        if (mLocationClient.isConnected()) {
            stopLocationUpdates(); 
        } 
        mLocationClient.disconnect();
 
        super.onStop(); 
    } 
 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present. 
        getMenuInflater().inflate(R.menu.main, menu);
        return true; 
    } 
 

6
CodeRank
This code example shows how to use the following methods:connect, isConnected, isConnecting
	 *  
	 * @return A LocationClient object 
	 */ 
	protected GooglePlayServicesClient getLocationClient() {
		if (this.locationServices == null) {
			this.locationServices = new LocationClient(this.context, this, this);
		} 
		if (!this.locationServices.isConnected() && !this.locationServices.isConnecting()) {
			// This call returns immediately, but the request is not complete 
			// until onConnected() or onConnectionFailure() is called. 
			this.locationServices.connect();
		} 
		return this.locationServices;
	} 
	 
	protected void terminateLocationClient() { 
		if (this.locationServices != null) {
			if (this.locationServices.isConnected()) {
				this.locationServices.disconnect();
			} 
6
CodeRank
This code example shows how to use the following methods:disconnect, isConnected, removeLocationUpdates
 
    @Override 
    public void onDestroy() { 
        Log.d(TAG, "onDestroy()");
 
        if (mLocationClient != null && mLocationClient.isConnected()) {
            mLocationClient.removeLocationUpdates(this);
            mLocationClient.disconnect();
        } 
        super.onDestroy(); 
    } 
 
    @Override 
    public void onLocationChanged(Location location) {
    	Intent intent = new Intent(ACTION_NEW_LOCATION).putExtra(EXTRA_LOCATION, location);
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
    } 
 
    private boolean servicesAvailable() { 
        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
6
CodeRank
This code example shows how to use the following methods:
     * @return A LocationClient object 
     */ 
    private GooglePlayServicesClient getLocationClient() {
        if (mLocationClient == null) {
 
            mLocationClient = new LocationClient(mActivity, this, this);
        } 
        return mLocationClient;
 
    } 
    /** 
     * Once the connection is available, send a request to add the Geofences 
     */ 
    private void continueAddGeofences() { 
 
        // Get a PendingIntent that Location Services issues when a geofence transition occurs 
        mGeofencePendingIntent = createRequestPendingIntent();
 
        // Send a request to add the current geofences 
        mLocationClient.addGeofences(mCurrentGeofences, mGeofencePendingIntent, this);
6
CodeRank
This code example shows how to use the following methods:connect
  @Override 
  protected void onResume() { 
    super.onResume(); 
    setUpMapIfNeeded(); 
    setUpLocationClientIfNeeded(); 
    mLocationClient.connect();
  } 
 
  @Override 
  public void onPause() { 
    super.onPause(); 
    if (mLocationClient != null) {
      mLocationClient.disconnect();
    } 
  } 
 
  private void setUpMapIfNeeded() { 
    // Do a null check to confirm that we have not already instantiated the map. 
    if (mMap == null) {
      // Try to obtain the map from the SupportMapFragment. 

6
CodeRank
This code example shows how to use the following methods:connect
	@SuppressWarnings("unchecked") 
	public GeoFusedSucker(Context context) {
		super(context);
		setSucker(this);
		 
		mLocationClient = new LocationClient(context, this, this);
		mLocationClient.connect();
		 
		 
	} 
	 
	public ILogPack forceReturn() { 
		double[] loc = updateLocation();
		if(loc == null) {
			Log.d(LOG, "location was null");
			loc = new double[] {0d, 0d};
		} 
		 
		return new ILogPack(Geo.Keys.GPS_COORDS, "[" + loc[0] + "," + loc[1] + "]");
	} 
6
CodeRank
This code example shows how to use the following methods:connect, isConnected, isConnecting
 
    /** 
     * Start location updates. 
     */ 
    public void start() { 
        if (!locationClient.isConnected() && !locationClient.isConnecting()) {
            locationClient.connect();
        } 
    } 
 
    @Override 
    public void onConnected(Bundle bundle) {
        LocationRequest locationRequest = LocationRequest.create();
        locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        locationRequest.setInterval(UPDATE_INTERVAL);
        locationRequest.setFastestInterval(UPDATE_INTERVAL);
        locationRequest.setSmallestDisplacement(1);
 
        requestNotifyLastKnownLocation(); 
 
5
CodeRank
This code example shows how to use the following methods:connect, getLastLocation, requestLocationUpdates
    	locationClient.connect();
    } 
 
     
    private void retrieveLocationUsingListener() { 
    	locationClient.connect();
    	Location lastLocation = locationClient.getLastLocation();
    	 
    	System.out.println("Found location " + lastLocation);
    	 
    	LocationRequest locationRequest = LocationRequest.create().setInterval(5000).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    	 
    	 
    	locationClient.requestLocationUpdates(locationRequest, locationListener);
    	 
    } 
     
    private LocationListener locationListener = new LocationListener() {
 
		@Override 
5
CodeRank
This code example shows how to use the following methods:disconnect, isConnected, removeLocationUpdates
     */ 
    @Override 
    public void onDestroy() { 
        Log.d(TAG, "onDestroy");
        // If the client is connected 
        if (mLocationClient.isConnected()) {
            Intent intent = new Intent(this,LocationUpdatesIntentService.class);
            PendingIntent pIntent = PendingIntent.getService(this, 0, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mLocationClient.removeLocationUpdates(pIntent);
 
            //mLocationClient.removeLocationUpdates(this); 
        } 
 
        // After disconnect() is called, the client is considered "dead". 
        mLocationClient.disconnect();
 
        //wakeLock.release(); 
        super.onDestroy(); 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:disconnect, isConnected, removeLocationUpdates
	@Override 
	public void onDestroy(){ 
		super.onDestroy(); 
		Log.d(TAG, "onDestroy: BG");
		 
		if(locationClient != null && locationClient.isConnected()) {
			locationClient.removeLocationUpdates(this);
			locationClient.disconnect();
		} 
	} 
 
	@Override 
	public void onConnected(Bundle arg0) {
		Log.d(TAG, "onConnected: BG");
		 
		Long time = 60*1000L;
		 
		LocationRequest locationRequest = LocationRequest.create();
		locationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
		locationRequest.setInterval(time);
5
CodeRank

Related Android LocationClient Questions & Answers:

See Code Examples for Android LocationClient Methods: