private LocationRequest getLocationRequest() {
   LocationRequest lr =
       LocationRequest.create()
           .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
           .setInterval(LOCATION_UPDATE_INTERVAL);
   if (!mConstantReporting) {
     lr.setNumUpdates(MAX_LOCATION_UPDATES);
   }
   return lr;
 }
Exemplo n.º 2
0
  public LocationRequest createLocationRequest() {
    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(UPDATE_INTERVAL);
    locationRequest.setFastestInterval(FASTEST_INTERVAL);
    locationRequest.setExpirationDuration(ACCEPTED_LOCATION_AGE_MILLIS);
    locationRequest.setNumUpdates(5);

    return locationRequest;
  }
Exemplo n.º 3
0
  /** @brief This function starts the GPS */
  private void startLocation(boolean quick) {
    // Check if we need to set up Google API
    if (!sGPSIsOn) {
      Log.e(TAG, "starting location?");
      if (sGoogleApi == null) {
        // Build API
        sGoogleApi =
            new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();

        // Thank the 6 God for blockingConnect
        ConnectionResult what = sGoogleApi.blockingConnect();
      }

      if (sLocationIntent == null) {
        Intent intent = new Intent(this, InnerLocationService.class);
        sLocationIntent =
            PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      }

      if (quick) {
        sQuickGPSIsOn = true;
      }

      long interval = quick ? 0 : 20000;
      LocationRequest locRequest = new LocationRequest();
      if (quick) {
        sQuickGPSIsOn = true;
        locRequest.setNumUpdates(2);
      }

      locRequest.setInterval(interval);
      locRequest.setFastestInterval(interval);
      locRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
      LocationServices.FusedLocationApi.requestLocationUpdates(
          sGoogleApi, locRequest, sLocationIntent);
      sGPSIsOn = true;
    }
  }