Java Code Examples for com.google.android.gms.location.LocationRequest#PRIORITY_HIGH_ACCURACY

The following examples show how to use com.google.android.gms.location.LocationRequest#PRIORITY_HIGH_ACCURACY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivityRecognitionLocationProvider.java    From background-geolocation-android with Apache License 2.0 6 votes vote down vote up
/**
 * Translates a number representing desired accuracy of Geolocation system from set [0, 10, 100, 1000].
 * 0:  most aggressive, most accurate, worst battery drain
 * 1000:  least aggressive, least accurate, best for battery.
 */
private Integer translateDesiredAccuracy(Integer accuracy) {
    if (accuracy >= 10000) {
        return LocationRequest.PRIORITY_NO_POWER;
    }
    if (accuracy >= 1000) {
        return LocationRequest.PRIORITY_LOW_POWER;
    }
    if (accuracy >= 100) {
        return LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
    }
    if (accuracy >= 10) {
        return LocationRequest.PRIORITY_HIGH_ACCURACY;
    }
    if (accuracy >= 0) {
        return LocationRequest.PRIORITY_HIGH_ACCURACY;
    }

    return LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
}
 
Example 2
Source File: FusedLocationModule.java    From react-native-fused-location with MIT License 6 votes vote down vote up
@ReactMethod
public void setLocationPriority(int mLocationPriority) {
    switch (mLocationPriority) {
        case 0:
            this.mLocationPriority = LocationRequest.PRIORITY_HIGH_ACCURACY;
            break;
        case 1:
            this.mLocationPriority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
            break;
        case 2:
            this.mLocationPriority = LocationRequest.PRIORITY_LOW_POWER;
            break;
        case 3:
            this.mLocationPriority = LocationRequest.PRIORITY_NO_POWER;
            break;
    }
}
 
Example 3
Source File: BackgroundLocationUpdateService.java    From cordova-background-geolocation-services with Apache License 2.0 6 votes vote down vote up
/**
 * Translates a number representing desired accuracy of GeoLocation system from set [0, 10, 100, 1000].
 * 0:  most aggressive, most accurate, worst battery drain
 * 1000:  least aggressive, least accurate, best for battery.
 */
private Integer translateDesiredAccuracy(Integer accuracy) {
    if(accuracy <= 0) {
        accuracy = LocationRequest.PRIORITY_HIGH_ACCURACY;
    } else if(accuracy <= 100) {
        accuracy = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
    } else if(accuracy  <= 1000) {
        accuracy = LocationRequest.PRIORITY_LOW_POWER;
    } else if(accuracy <= 10000) {
        accuracy = LocationRequest.PRIORITY_NO_POWER;
    } else {
      accuracy = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
    }

    return accuracy;
}
 
Example 4
Source File: AndroidLocationPlayServiceManager.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
private void setupBackgroundLocationRequest(LocationRequest req) {
    Display d = Display.getInstance();
    String priorityStr = d.getProperty("android.backgroundLocation.priority", "PRIORITY_BALANCED_POWER_ACCURACY");
    String fastestIntervalStr = d.getProperty("android.backgroundLocation.fastestInterval", "5000");
    String intervalStr = d.getProperty("android.backgroundLocation.interval", "10000");
    String smallestDisplacementStr = d.getProperty("android.backgroundLocation.smallestDisplacement", "50");

    int priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
    if ("PRIORITY_HIGH_ACCURACY".equals(priorityStr)) {
        priority = LocationRequest.PRIORITY_HIGH_ACCURACY;
    } else if ("PRIORITY_LOW_POWER".equals(priorityStr)) {
        priority = LocationRequest.PRIORITY_LOW_POWER;
    } else if ("PRIORITY_NO_POWER".equals(priorityStr)) {
        priority = LocationRequest.PRIORITY_NO_POWER;
    }

    long interval = Long.parseLong(intervalStr);
    long fastestInterval = Long.parseLong(fastestIntervalStr);
    int smallestDisplacement = Integer.parseInt(smallestDisplacementStr);

    req.setPriority(priority)
            .setFastestInterval(fastestInterval)
            .setInterval(interval)
            .setSmallestDisplacement(smallestDisplacement);
}
 
Example 5
Source File: NativeLocationClientImpl.java    From android_external_GmsLib with Apache License 2.0 6 votes vote down vote up
private static Criteria makeNativeCriteria(LocationRequest request) {
    Criteria criteria = new Criteria();
    switch (request.getPriority()) {
        case LocationRequest.PRIORITY_HIGH_ACCURACY:
            criteria.setAccuracy(Criteria.ACCURACY_FINE);
            criteria.setPowerRequirement(Criteria.POWER_HIGH);
            break;
        case LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY:
        default:
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);
            criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
            break;
        case LocationRequest.PRIORITY_NO_POWER:
        case LocationRequest.PRIORITY_LOW_POWER:
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);
            criteria.setPowerRequirement(Criteria.POWER_LOW);
    }
    return criteria;
}
 
Example 6
Source File: GoogleLocationEngineImpl.java    From mapbox-events-android with MIT License 5 votes vote down vote up
private static int toGMSLocationPriority(int enginePriority) {
  switch (enginePriority) {
    case LocationEngineRequest.PRIORITY_HIGH_ACCURACY:
      return LocationRequest.PRIORITY_HIGH_ACCURACY;
    case LocationEngineRequest.PRIORITY_BALANCED_POWER_ACCURACY:
      return LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
    case LocationEngineRequest.PRIORITY_LOW_POWER:
      return LocationRequest.PRIORITY_LOW_POWER;
    case LocationEngineRequest.PRIORITY_NO_POWER:
    default:
      return LocationRequest.PRIORITY_NO_POWER;
  }
}
 
Example 7
Source File: LocationSwitch.java    From react-native-location-switch with Apache License 2.0 5 votes vote down vote up
public void setup(final Callback successCallback, final Callback errorCallback,
                  final int interval, final boolean requestHighAccuracy) {
    mInterval = interval;
    mErrorCallback = errorCallback;
    mSuccessCallback = successCallback;

    if (requestHighAccuracy) {
        mAccuracy = LocationRequest.PRIORITY_HIGH_ACCURACY;
    } else {
        mAccuracy = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
    }
}
 
Example 8
Source File: GpsConfig.java    From RxGpsService with Apache License 2.0 5 votes vote down vote up
GpsConfig(Activity activity) {
  this.activity = activity;
  this.debugMode = false;
  this.stageDistance = 0;
  this.minDistanceTraveled = 10;
  this.speedMinModeAuto = 5 / 3.6f;
  this.discardSpeedsAbove = 150 / 3.6f;
  this.priority = LocationRequest.PRIORITY_HIGH_ACCURACY;
  this.interval = 10000;
  this.fastestInterval = 5000;
}
 
Example 9
Source File: RNFusedLocationModule.java    From react-native-geolocation-service with MIT License 4 votes vote down vote up
/**
 * Get the current position. This can return almost immediately if the location is cached or
 * request an update, which might take a while.
 *
 * @param options map containing optional arguments: timeout (millis), maximumAge (millis),
 *                highAccuracy (boolean), distanceFilter (double) and showLocationDialog (boolean)
 * @param success success callback
 * @param error   error callback
 */
@ReactMethod
public void getCurrentPosition(ReadableMap options, final Callback success, final Callback error) {
  ReactApplicationContext context = getContext();

  mSuccessCallback = success;
  mErrorCallback = error;

  if (!LocationUtils.hasLocationPermission(context)) {
    invokeError(
      LocationError.PERMISSION_DENIED.getValue(),
      "Location permission not granted.",
      true
    );
    return;
  }

  if (!LocationUtils.isGooglePlayServicesAvailable(context)) {
    invokeError(
      LocationError.PLAY_SERVICE_NOT_AVAILABLE.getValue(),
      "Google play service is not available.",
      true
    );
    return;
  }

  boolean highAccuracy = options.hasKey("enableHighAccuracy") &&
    options.getBoolean("enableHighAccuracy");

  // TODO: Make other PRIORITY_* constants available to the user
  mLocationPriority = highAccuracy ? LocationRequest.PRIORITY_HIGH_ACCURACY : DEFAULT_ACCURACY;

  mTimeout = options.hasKey("timeout") ? (long) options.getDouble("timeout") : Long.MAX_VALUE;
  mMaximumAge = options.hasKey("maximumAge")
    ? options.getDouble("maximumAge")
    : Double.POSITIVE_INFINITY;
  mDistanceFilter = options.hasKey("distanceFilter")
    ? (float) options.getDouble("distanceFilter")
    : 0;
  mShowLocationDialog = options.hasKey("showLocationDialog")
    ? options.getBoolean("showLocationDialog")
    : true;
  mForceRequestLocation = options.hasKey("forceRequestLocation")
    ? options.getBoolean("forceRequestLocation")
    : false;

  LocationSettingsRequest locationSettingsRequest = buildLocationSettingsRequest();

  if (mSettingsClient != null) {
    mSettingsClient.checkLocationSettings(locationSettingsRequest)
      .addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {
        @Override
        public void onComplete(@NonNull Task<LocationSettingsResponse> task) {
          onLocationSettingsResponse(task, true);
        }
      });
  }
}
 
Example 10
Source File: RNFusedLocationModule.java    From react-native-geolocation-service with MIT License 4 votes vote down vote up
/**
 * Start listening for location updates. These will be emitted via the
 * {@link RCTDeviceEventEmitter} as {@code geolocationDidChange} events.
 *
 * @param options map containing optional arguments: highAccuracy (boolean), distanceFilter (double),
 *                interval (millis), fastestInterval (millis)
 */
@ReactMethod
public void startObserving(ReadableMap options) {
  ReactApplicationContext context = getContext();

  if (!LocationUtils.hasLocationPermission(context)) {
    invokeError(
      LocationError.PERMISSION_DENIED.getValue(),
      "Location permission not granted.",
      false
    );
    return;
  }

  if (!LocationUtils.isGooglePlayServicesAvailable(context)) {
    invokeError(
      LocationError.PLAY_SERVICE_NOT_AVAILABLE.getValue(),
      "Google play service is not available.",
      false
    );
    return;
  }

  boolean highAccuracy = options.hasKey("enableHighAccuracy")
    && options.getBoolean("enableHighAccuracy");

  // TODO: Make other PRIORITY_* constants available to the user
  mLocationPriority = highAccuracy ? LocationRequest.PRIORITY_HIGH_ACCURACY : DEFAULT_ACCURACY;
  mDistanceFilter = options.hasKey("distanceFilter")
    ? (float) options.getDouble("distanceFilter")
    : DEFAULT_DISTANCE_FILTER;
  mUpdateInterval = options.hasKey("interval")
    ? (long) options.getDouble("interval")
    : DEFAULT_INTERVAL;
  mFastestInterval = options.hasKey("fastestInterval")
    ? (long) options.getDouble("fastestInterval")
    : DEFAULT_INTERVAL;
  mShowLocationDialog = options.hasKey("showLocationDialog")
    ? options.getBoolean("showLocationDialog")
    : true;
  mForceRequestLocation = options.hasKey("forceRequestLocation")
    ? options.getBoolean("forceRequestLocation")
    : false;

  LocationSettingsRequest locationSettingsRequest = buildLocationSettingsRequest();

  if (mSettingsClient != null) {
    mSettingsClient.checkLocationSettings(locationSettingsRequest)
      .addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {
        @Override
        public void onComplete(@NonNull Task<LocationSettingsResponse> task) {
          onLocationSettingsResponse(task, false);
        }
      });
  }
}