Java 类com.google.android.gms.location.LocationListener 实例源码

项目:1617PROJ1Bloeddonatie-app    文件:MainActivity.java   
private void startLocationMoitoring() {
    if (googleApiClient.isConnected()) {
        LocationRequest locationRequest = LocationRequest.create()
            .setInterval(10000)
            .setFastestInterval(5000)
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                Log.d(TAG, "location update");
                currentLocation = location;
            }
        });
    }
}
项目:Leanplum-Android-SDK    文件:LeanplumLocationManagerTest.java   
/**
 * Tests for requestLocation.
 *
 * @throws Exception
 */
@Test
public void requestLocation() throws Exception {
  GoogleApiClient mockGoogleApiClient = mock(GoogleApiClient.class);
  doReturn(true).when(mockGoogleApiClient).isConnected();

  LocationManager mockLocationManager = spy(mLocationManager);
  Whitebox.setInternalState(mockLocationManager, "googleApiClient", mockGoogleApiClient);

  FusedLocationProviderApi mockLocationProviderApi = mock(FusedLocationProviderApi.class);
  Whitebox.setInternalState(LocationServices.class, "FusedLocationApi", mockLocationProviderApi);

  // Testing when a customer did not disableLocationCollection.
  Whitebox.invokeMethod(mockLocationManager, "requestLocation");
  verify(mockLocationProviderApi).requestLocationUpdates(any(GoogleApiClient.class),
      any(LocationRequest.class), any(LocationListener.class));

  // Testing when a customer disableLocationCollection.
  Leanplum.disableLocationCollection();
  Whitebox.invokeMethod(mockLocationManager, "requestLocation");
  verifyNoMoreInteractions(mockLocationProviderApi);
}
项目:Android-Programming-BigNerd    文件:LocatrFragment.java   
private void findImage() {
    LocationRequest request = LocationRequest.create();
    request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    request.setNumUpdates(1);
    request.setInterval(0);
    try {
        LocationServices.FusedLocationApi.requestLocationUpdates(mClient, request,
                new LocationListener() {
                    @Override
                    public void onLocationChanged(Location location) {
                        Log.d(TAG, "onLocationChanged: " + location.getLatitude() + ", " +
                                location.getLongitude());
                        new SearchTask().execute(location);
                    }
                });
    } catch (SecurityException e) {
        if (DEBUG) {
            Log.e(TAG, "no permission", e);
        }
    }
}
项目:ITagAntiLost    文件:LocationChangeService.java   
private void startLocationUpdate(
    GoogleApiClient googleApiClient,
    LocationListener locationListener
) {
  boolean a = ActivityCompat.checkSelfPermission(getApplicationContext(),
      Manifest.permission.ACCESS_FINE_LOCATION
  ) != PackageManager.PERMISSION_GRANTED;
  boolean b = ActivityCompat.checkSelfPermission(getApplicationContext(),
      Manifest.permission.ACCESS_COARSE_LOCATION
  ) != PackageManager.PERMISSION_GRANTED;
  if (a && b) {
    googleApiClient.disconnect();
    return;
  }
  LocationServices.FusedLocationApi.requestLocationUpdates(
      googleApiClient,
      new LocationRequest().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY),
      locationListener);
}
项目:Dryver    文件:ActivityRequestMap.java   
@Override
public void onConnected(Bundle bundle) {
    initializeLocationRequest(10, 1000);
    LocationServices.FusedLocationApi.requestLocationUpdates(mClient, mLocationRequest, new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            currentLocation = location;
            mapUtil.moveMap(mMap, currentLocation, 15);
        }
    });

    currentLocation = LocationServices.FusedLocationApi.getLastLocation(mClient);
    if (currentLocation != null) {
        mapUtil.moveMap(mMap, currentLocation, 15);
    }
}
项目:Popdeem-SDK-Android    文件:PDUISocialMultiLoginFragment.java   
private void startLocationManagerAfterLogin() {
    mProgressFacebook.setVisibility(View.VISIBLE);

    mFacebookLoginButton.setVisibility(View.INVISIBLE);
    mTwitterLoginButton.setVisibility(View.INVISIBLE);
    mInstaLoginButton.setVisibility(View.INVISIBLE);

    mLocationManager.startLocationUpdates(new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            if (location != null) {
                handleLocationUpdate(location);
            }
        }
    });
}
项目:corsaire    文件:MyAddressService.java   
@Override
public void onConnected(@Nullable Bundle bundle) {
    LocationRequest mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(2000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(mLocationRequest);
    LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient,
            builder.build());
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {

        }
    });
}
项目:FastFoodFinder    文件:StoreDetailActivity.java   
@SuppressWarnings("MissingPermission")
@Override
public void onConnected(@Nullable Bundle bundle) {
    if (PermissionUtils.isLocationPermissionGranted(this)) {
        LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, mLocationRequest, new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                currLocation = new LatLng(location.getLatitude(), location.getLongitude());
                // Creating a LatLng object for the current location
            }
        });

        Location lastLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
        if (lastLocation != null) {
            currLocation = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude());
        } else
            Toast.makeText(StoreDetailActivity.this, "Cannot get current location!", Toast.LENGTH_SHORT).show();
    } else {
        PermissionUtils.requestLocaiton(this);
    }
}
项目:drone-onboard-app    文件:LocationService.java   
public void startLocationListening(Context context, LocationListener locationListener) {
    this.context = context;
    this.locationListener = locationListener;
    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(context)
                .addConnectionCallbacks(this)
                .addApi(LocationServices.API)
                .build();

    }
    mGoogleApiClient.connect();

    mLocationRequest = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(MIN_UPDATE_INTERVAL_IN_SECONDS * 1000);
}
项目:PrayTime-Android    文件:LocationHelper.java   
private void checkLocationAndInit() {
  if (sLastLocation == null) {
    sLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
  }

  if (sLastLocation == null) {
    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, createLocationRequest(), new LocationListener() {
      @Override
      public void onLocationChanged(Location location) {
        sLastLocation = location;
        if (mCallback != null) {
          mCallback.onLocationChanged(sLastLocation);
        }
        initAppAfterCheckingLocation();
        LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
      }
    });

  } else {
    initAppAfterCheckingLocation();
  }
}
项目:rxactivityresponse    文件:LocationObservable.java   
@SuppressLint("MissingPermission")
@Override
protected void locationSettingSuccess(final ResourceObserver<Location> emitter, GoogleApiClient client) {
    this.client = client;
    locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            emitter.onNext(location);
            if (locationRequest.getNumUpdates() == 1) {
                emitter.onComplete();
            }
        }
    };

    //noinspection MissingPermission
    LocationServices.FusedLocationApi.requestLocationUpdates(client, locationRequest, locationListener);
}
项目:sprockets-android    文件:GoogleLocationProvider.java   
@Override
@RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
public Observable<Location> requestLocationUpdates(LocationRequest request) {
    return Observable.create(emitter -> {
        GoogleApiClient client = mBuilder.build();
        LocationListener listener = emitter::onNext;
        GoogleApiClients.connect(client, hint -> FusedLocationApi
                .requestLocationUpdates(client, request, listener, Loopers.nullOrMain())
                .setResultCallback(status -> {
                    if (!status.isSuccess()) {
                        emitter.onComplete();
                    }
                }), result -> emitter.onComplete());
        emitter.setCancellable(() -> {
            if (client.isConnected()) {
                FusedLocationApi.removeLocationUpdates(client, listener);
            }
            client.disconnect();
        });
    });
}
项目:android_external_GmsLib    文件:LocationClientImpl.java   
public void requestLocationUpdates(LocationRequest request, final LocationListener listener)
        throws RemoteException {
    if (nativeLocation != null) {
        nativeLocation.requestLocationUpdates(request, listener);
    } else {
        if (!listenerMap.containsKey(listener)) {
            listenerMap.put(listener, new ILocationListener.Stub() {
                @Override
                public void onLocationChanged(Location location) throws RemoteException {
                    listener.onLocationChanged(location);
                }
            });
        }
        getServiceInterface().requestLocationUpdatesWithPackage(request,
                listenerMap.get(listener), getContext().getPackageName());
    }
}
项目:QuizUpWinner    文件:gm.java   
public void requestLocationUpdates(LocationRequest paramLocationRequest, LocationListener paramLocationListener, Looper paramLooper)
{
  this.xP.bP();
  if (paramLooper == null)
    eg.b(Looper.myLooper(), "Can't create handler inside thread that has not called Looper.prepare()");
  synchronized (this.xS)
  {
    b localb1 = (b)this.xS.get(paramLocationListener);
    b localb2 = localb1;
    if (localb1 == null)
      localb2 = new b(paramLocationListener, paramLooper);
    this.xS.put(paramLocationListener, localb2);
    try
    {
      ((gl)this.xP.bQ()).a(paramLocationRequest, localb2, this.mContext.getPackageName());
    }
    catch (RemoteException localRemoteException)
    {
      throw new IllegalStateException(localRemoteException);
    }
    return;
  }
}
项目:GitHub    文件:LocationUpdatesObservable.java   
@Override
protected void onGoogleApiClientReady(GoogleApiClient apiClient, final Observer<? super Location> observer) {
    listener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            observer.onNext(location);
        }
    };
    LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, listener);
}
项目:RxJava2-weather-example    文件:LocationUpdatesFlowableOnSubscribe.java   
@Override
protected void onGoogleApiClientReady(GoogleApiClient apiClient, final FlowableEmitter<Location> emitter) {
    locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location value) {
            emitter.onNext(value);
        }
    };

    //noinspection MissingPermission
    setupLocationPendingResult(
            LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, locationListener, looper),
            new StatusErrorResultCallBack(emitter)
    );
}
项目:IM_Here    文件:MapActivityFragment.java   
@Override
public void onConnected(LocationListener locationListener) {
    LocationRequest locationRequest = new LocationRequest()
            .setInterval(Constants.ACTIVITY_MODE)
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    try {
        LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, locationListener);
    }catch(SecurityException e){

    }
}
项目:oma-riista-android    文件:LocationClient.java   
public void addListener(LocationListener listener) {
    if (mListeners.isEmpty() && listener != null && mGoogleApiClient != null) {
        mGoogleApiClient.connect();
    }

    mListeners.add(listener);
}
项目:oma-riista-android    文件:LocationClient.java   
public void removeListener(LocationListener listener) {
    mListeners.remove(listener);

    if (mListeners.isEmpty() && mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
        mGoogleApiClient.disconnect();
    }
}
项目:AndroidProgramming3e    文件:LocatrFragment.java   
private void findImage() {
    LocationRequest request = LocationRequest.create();
    request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    request.setNumUpdates(1);
    request.setInterval(0);
    LocationServices.FusedLocationApi
            .requestLocationUpdates(mClient, request, new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    Log.i(TAG, "Got a fix: " + location);
                    new SearchTask().execute(location);
                }
            });
}
项目:AndroidProgramming3e    文件:LocatrFragment.java   
private void findImage() {
    LocationRequest request = LocationRequest.create();
    request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    request.setNumUpdates(1);
    request.setInterval(0);
    LocationServices.FusedLocationApi
            .requestLocationUpdates(mClient, request, new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    Log.i(TAG, "Got a fix: " + location);
                    new SearchTask().execute(location);
                }
            });
}
项目:piast-trail    文件:PlaceListFragment.java   
private void findCoords() {
    LocationRequest request = LocationRequest.create();
    request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    request.setNumUpdates(1);
    request.setInterval(0);

    LocationServices.FusedLocationApi
            .requestLocationUpdates(mClient, request, new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    double lat = location.getLatitude();
                    double lon = location.getLongitude();
                    mLocation.setLatitude(lat);
                    mLocation.setLongitude(lon);
                    mWasLocationFixed = true;

                    //Sort the order in which places are shown
                    //depending on how far they are from us (= by distance ascending)
                    Collections.sort(mPlaces, new Comparator<Visitable>() {
                        @Override
                        public int compare(Visitable a, Visitable b) {
                            Location aLoc = a.getLocation();
                            Location bLoc = b.getLocation();
                            return (int) aLoc.distanceTo(mLocation) - (int) bLoc.distanceTo(mLocation);
                        }
                    });
                    mAdapter.setPlaces(mPlaces);
                    mAdapter.notifyDataSetChanged();
                }
            });
}
项目:ITagAntiLost    文件:LocationChangeService.java   
@Override
protected void onHandleIntent(Intent intent) {
  if (intent != null) {
    final String address = intent.getStringExtra(BleService.DEVICE_ADDRESS);
    if (address != null) {
      final GoogleApiClient googleApiClient =
          new GoogleApiClient.Builder(getApplicationContext())
              .addApi(LocationServices.API)
              .build();

      final LocationListener locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(final Location location) {
          if (location != null) {
            updateDeviceLocation(address, location);
            LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, this);
            googleApiClient.disconnect();
          }
        }
      };

      googleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
        @Override
        public void onConnected(@Nullable Bundle bundle) {
          startLocationUpdate(googleApiClient, locationListener);
        }

        @Override
        public void onConnectionSuspended(int i) {

        }
      });
      googleApiClient.connect();
    }
  }
}
项目:SjekkUT    文件:MainActivity.java   
@Override
public void onConnected(Bundle bundle) {
    for (LocationListener listener : mPendingListener.keySet()) {
        startLocationUpdates(listener, mPendingListener.get(listener));
    }
    mPendingListener.clear();
    if (getIntent() != null && getIntent().hasExtra(EXTRA_GEOFENCE_PLACE_ID)) {
        LocationServices.GeofencingApi.removeGeofences(
                mGoogleApiClient,
                Collections.singletonList(getIntent().getStringExtra(EXTRA_GEOFENCE_PLACE_ID))
        );
        getIntent().removeExtra(EXTRA_GEOFENCE_PLACE_ID);
    }
}
项目:SjekkUT    文件:MainActivity.java   
void startLocationUpdates(LocationListener listener, LocationRequest locationRequest) {
    if (mGoogleApiClient.isConnected()) {
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, listener);
    } else {
        mPendingListener.put(listener, locationRequest);
    }
}
项目:SjekkUT    文件:MainActivity.java   
void stopLocationUpdates(LocationListener listener) {
    if (mGoogleApiClient.isConnected()) {
        LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, listener);
    } else {
        mPendingListener.remove(listener);
    }
}
项目:Dryver    文件:ActivityDryverMap.java   
/**
 * Overriding Callback {@link GoogleApiClient.ConnectionCallbacks} onConnected and finds the
 * current location of the user using {@link LocationRequest} and location services
 *
 * @param bundle
 * @see com.google.android.gms.location.FusedLocationProviderApi
 * @see GoogleApiClient
 */
@Override
public void onConnected(Bundle bundle) {
    initializeLocationRequest(1, 1000);
    LocationServices.FusedLocationApi.requestLocationUpdates(mClient, mLocationRequest, new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            currentLocation = location;
        }
    });

    currentLocation = LocationServices.FusedLocationApi.getLastLocation(mClient);
}
项目:Dryver    文件:ActivityDryverMain.java   
/**
 * Find the device's current location using location services
 *
 * @see LocationRequest
 * @see LocationServices
 * @see com.google.android.gms.location.FusedLocationProviderApi
 */
public void findCurrentLocation() {
    currentLocation = LocationServices.FusedLocationApi.getLastLocation(mClient);
    Log.i("ActivityDryverMain: ", "CURRENT LOCATION: " + currentLocation);

    //CODE BELOW IS FOR CONTINUOUSLY UPDATING USER LOCATION
    LocationServices.FusedLocationApi.requestLocationUpdates(mClient, mLocationRequest, new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            currentLocation = location;
            Log.i("ActivityDryverMain: ", "NEW LOCATION: " + location);
        }
    });
}
项目:appez-android    文件:LocationServiceOld.java   
@SuppressLint("HandlerLeak")
private void getCurrentLocation() {
    if (isLocationServiceEnabled) {
        handleLocationRequestTimeout();
        int resp = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
        Log.d(SmartConstants.APP_NAME, "LocationService->play services:" + resp);
        if (resp == ConnectionResult.SUCCESS) {
            locationclient = new LocationClient(context, this, this);
            locationclient.connect();
            showProgressDialog();
            final LocationListener locListener = this;

            Handler locationHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    locationrequest = LocationRequest.create();
                    locationrequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
                    locationrequest.setInterval(TIME_INTERVAL_BW_REQUESTS);
                    locationrequest.setNumUpdates(1);
                    locationclient.requestLocationUpdates(locationrequest, locListener);
                }
            };
            locationHandler.sendEmptyMessageDelayed(0, 1000);

        } else {
            onErrorLocationOperation(ExceptionTypes.LOCATION_ERROR_PLAY_SERVICE_NOT_AVAILABLE, ExceptionTypes.LOCATION_ERROR_PLAY_SERVICE_NOT_AVAILABLE_MESSAGE);
        }
    } else {
        // Means that the location service of the device is not turned on
        // Prompt the user to turn on the Location service
        showDecisionDialog("Location Service Disabled", "Location service is disabled in your device. Enable it?", "Enable Location", "No");
    }
}
项目:Forage    文件:LocationAsyncEmitter.java   
@Override
public void call(AsyncEmitter<Location> locationAsyncEmitter) {

    LocationListener locationListener = locationAsyncEmitter::onNext;

    GoogleApiClient.OnConnectionFailedListener onConnectionFailedListener = connectionResult ->
            locationAsyncEmitter.onError(new LocationUnavailableException("Failed to connect to Google Play Services!"));

    GoogleApiClient.ConnectionCallbacks connectionCallbacks = new GoogleApiClient.ConnectionCallbacks() {
        @Override
        public void onConnected(@Nullable Bundle bundle) {
            try {
                LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, locationListener);
            } catch (SecurityException e) {
                locationAsyncEmitter.onError(new LocationUnavailableException("Location permission not available!"));
            }
        }

        @Override
        public void onConnectionSuspended(int i) {
            locationAsyncEmitter.onError(new LocationUnavailableException("Connection lost to Google Play Services"));

        }
    };

    googleApiClient.registerConnectionCallbacks(connectionCallbacks);
    googleApiClient.registerConnectionFailedListener(onConnectionFailedListener);
    googleApiClient.connect();

    locationAsyncEmitter.setCancellation(() -> {
        LocationAsyncEmitter.this.locationRequest = null;
        LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, locationListener);
        googleApiClient.unregisterConnectionCallbacks(connectionCallbacks);
        googleApiClient.unregisterConnectionFailedListener(onConnectionFailedListener);
    });
}
项目:Popdeem-SDK-Android    文件:PDUISocialLoginFragment.java   
private void startLocationManagerAfterLogin() {
        mProgress.setVisibility(View.VISIBLE);
//        mLoginButton.setVisibility(View.INVISIBLE);
        mFacebookLoginButton.setVisibility(View.INVISIBLE);

        mLocationManager.startLocationUpdates(new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                if (location != null) {
                    handleLocationUpdate(location);
                }
            }
        });
    }
项目:Popdeem-SDK-Android    文件:PDUIConnectSocialAccountFragment.java   
private void startLocationManagerAfterLogin() {
    mLocationManager.startLocationUpdates(new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            if (location != null) {
                handleLocationUpdate(location);
            }
        }
    });
}
项目:Japp16    文件:LocationProviderService.java   
@Override
public void onLocationChanged(Location location) {
    lastLocation = location;
    LocationListener listener;
    for(int i = 0; i < listeners.size(); i++) {
        listener = listeners.get(i);
        if(listener != null) {
            listener.onLocationChanged(location);
        }
    }
}
项目:mytracks    文件:SearchListActivity.java   
/**
 * Handles the intent.
 * 
 * @param intent the intent
 */
private void handleIntent(Intent intent) {
  if (!Intent.ACTION_SEARCH.equals(intent.getAction())) {
    Log.e(TAG, "Invalid intent action: " + intent);
    finish();
    return;
  }

  final String textQuery = intent.getStringExtra(SearchManager.QUERY);
  setTitle(textQuery);

  final MyTracksLocationManager myTracksLocationManager = new MyTracksLocationManager(
      this, Looper.myLooper(), true);
  LocationListener locationListener = new LocationListener() {
      @Override
    public void onLocationChanged(final Location location) {
      myTracksLocationManager.close();
      new Thread() {
          @Override
        public void run() {
          SearchQuery query = new SearchQuery(
              textQuery, location, -1L, System.currentTimeMillis());
          doSearch(query);
        }
      }.start();
    }
  };
  myTracksLocationManager.requestLastLocation(locationListener);
}
项目:mytracks    文件:MyTracksLocationManager.java   
/**
 * Request last location.
 * 
 * @param locationListener location listener
 */
public void requestLastLocation(final LocationListener locationListener) {
  handler.post(new Runnable() {
      @Override
    public void run() {
      if (!isAllowed()) {
        requestLastLocation = null;
        locationListener.onLocationChanged(null);
      } else {
        requestLastLocation = locationListener;
        connectionCallbacks.onConnected(null);
      }
    }
  });
}
项目:mytracks    文件:MyTracksLocationManager.java   
/**
 * Requests location updates. This is an ongoing request, thus the caller
 * needs to check the status of {@link #isAllowed}.
 * 
 * @param minTime the minimal time
 * @param minDistance the minimal distance
 * @param locationListener the location listener
 */
public void requestLocationUpdates(
    final long minTime, final float minDistance, final LocationListener locationListener) {
  handler.post(new Runnable() {
      @Override
    public void run() {
      requestLocationUpdatesTime = minTime;
      requestLocationUpdatesDistance = minDistance;
      requestLocationUpdates = locationListener;
      connectionCallbacks.onConnected(null);
    }
  });
}
项目:mytracks    文件:MyTracksLocationManager.java   
/**
 * Removes location updates.
 * 
 * @param locationListener the location listener
 */
public void removeLocationUpdates(final LocationListener locationListener) {
  handler.post(new Runnable() {
      @Override
    public void run() {
      requestLocationUpdates = null;
      if (locationClient != null && locationClient.isConnected()) {
        locationClient.removeLocationUpdates(locationListener);
      }
    }
  });
}
项目:Android    文件:RecordActivityFragment.java   
/**
 * This method is called after an activity type is selected from the selectActivityType method
 */
protected void startLocationUpdates() {
    locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            //Only update location is we are recording
            if (recording) {
                updateLocation(location);
            }
        }
    };
    if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, locationListener);
    }
    Log.i("Development", "startLocationUpdates");
}
项目:go-bees    文件:LocationService.java   
/**
 * Configure parameters for requests to the fused location provider.
 *
 * @param callback LocationListener.
 */
void createLocationRequest(LocationListener callback) {
    locationRequest = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(UPDATE_INTERVAL)
            .setFastestInterval(FASTEST_INTERVAL);
    LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient,
            locationRequest, callback);
}
项目:go-bees    文件:LocationService.java   
/**
 * Start requesting location updates.
 *
 * @param listener LocationListener.
 */
void startLocationUpdates(LocationListener listener) {
    if (locationRequest != null) {
        LocationServices.FusedLocationApi.requestLocationUpdates(
                googleApiClient, locationRequest, listener);
    }
}