Java Code Examples for android.location.Criteria#setSpeedRequired()

The following examples show how to use android.location.Criteria#setSpeedRequired() . 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: LocationUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 获取定位参数对象
 * @return {@link Criteria}
 */
private static Criteria getCriteria() {
    Criteria criteria = new Criteria();
    // 设置定位精确度 Criteria.ACCURACY_COARSE 比较粗略, Criteria.ACCURACY_FINE 则比较精细
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    // 设置是否要求速度
    criteria.setSpeedRequired(false);
    // 设置是否允许运营商收费
    criteria.setCostAllowed(false);
    // 设置是否需要方位信息
    criteria.setBearingRequired(false);
    // 设置是否需要海拔信息
    criteria.setAltitudeRequired(false);
    // 设置对电源的需求
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    return criteria;
}
 
Example 2
Source File: RawLocationProvider.java    From background-geolocation-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onStart() {
    if (isStarted) {
        return;
    }

    Criteria criteria = new Criteria();
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setSpeedRequired(true);
    criteria.setCostAllowed(true);
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setHorizontalAccuracy(translateDesiredAccuracy(mConfig.getDesiredAccuracy()));
    criteria.setPowerRequirement(Criteria.POWER_HIGH);

    try {
        locationManager.requestLocationUpdates(locationManager.getBestProvider(criteria, true), mConfig.getInterval(), mConfig.getDistanceFilter(), this);
        isStarted = true;
    } catch (SecurityException e) {
        logger.error("Security exception: {}", e.getMessage());
        this.handleSecurityException(e);
    }
}
 
Example 3
Source File: LocationUtils.java    From Android-UtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * 设置定位参数
 *
 * @return {@link Criteria}
 */
private static Criteria getCriteria() {
    Criteria criteria = new Criteria();
    // 设置定位精确度 Criteria.ACCURACY_COARSE比较粗略,Criteria.ACCURACY_FINE则比较精细
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    // 设置是否要求速度
    criteria.setSpeedRequired(false);
    // 设置是否允许运营商收费
    criteria.setCostAllowed(false);
    // 设置是否需要方位信息
    criteria.setBearingRequired(false);
    // 设置是否需要海拔信息
    criteria.setAltitudeRequired(false);
    // 设置对电源的需求
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    return criteria;
}
 
Example 4
Source File: RxLocationTool.java    From RxTools-master with Apache License 2.0 6 votes vote down vote up
/**
 * 设置定位参数
 *
 * @return {@link Criteria}
 */
private static Criteria getCriteria() {
    Criteria criteria = new Criteria();
    //设置定位精确度 Criteria.ACCURACY_COARSE比较粗略,Criteria.ACCURACY_FINE则比较精细
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    //设置是否要求速度
    criteria.setSpeedRequired(false);
    // 设置是否允许运营商收费
    criteria.setCostAllowed(false);
    //设置是否需要方位信息
    criteria.setBearingRequired(false);
    //设置是否需要海拔信息
    criteria.setAltitudeRequired(false);
    // 设置对电源的需求
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    return criteria;
}
 
Example 5
Source File: Geolocation.java    From OsmGo with MIT License 6 votes vote down vote up
/**
 * Given the call's options, return a Criteria object
 * that will indicate which location provider we need to use.
 * @param call
 * @return
 */
private Criteria getCriteriaForCall(PluginCall call) {
  boolean enableHighAccuracy = call.getBoolean("enableHighAccuracy", false);
  boolean altitudeRequired = call.getBoolean("altitudeRequired", false);
  boolean speedRequired = call.getBoolean("speedRequired", false);
  boolean bearingRequired = call.getBoolean("bearingRequired", false);

  int timeout = call.getInt("timeout", 30000);
  int maximumAge = call.getInt("maximumAge", 0);

  Criteria c = new Criteria();
  c.setAccuracy(enableHighAccuracy ? Criteria.ACCURACY_FINE : Criteria.ACCURACY_COARSE);
  c.setAltitudeRequired(altitudeRequired);
  c.setBearingRequired(bearingRequired);
  c.setSpeedRequired(speedRequired);
  return c;
}
 
Example 6
Source File: LocationUtils.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * 设置定位参数
 *
 * @return {@link Criteria}
 */
private static Criteria getCriteria() {
    Criteria criteria = new Criteria();
    // 设置定位精确度 Criteria.ACCURACY_COARSE比较粗略,Criteria.ACCURACY_FINE则比较精细
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    // 设置是否要求速度
    criteria.setSpeedRequired(false);
    // 设置是否允许运营商收费
    criteria.setCostAllowed(false);
    // 设置是否需要方位信息
    criteria.setBearingRequired(false);
    // 设置是否需要海拔信息
    criteria.setAltitudeRequired(false);
    // 设置对电源的需求
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    return criteria;
}
 
Example 7
Source File: GPSTracker.java    From AsteroidOSSync with GNU General Public License v3.0 6 votes vote down vote up
public void updateLocation() {
    try {
        mLocationManager = (LocationManager) mContext
                .getSystemService(LOCATION_SERVICE);

        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_LOW);
        criteria.setSpeedRequired(false);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        String provider = mLocationManager.getBestProvider(criteria, true);
        if(provider != null) {
            mLocationManager.requestSingleUpdate(provider, this, null);
            mCanGetLocation = true;
        }
    }
    catch (SecurityException | NullPointerException e) {
        e.printStackTrace();
    }
}
 
Example 8
Source File: MapLocationUtil.java    From lunzi with Apache License 2.0 6 votes vote down vote up
private String getProvider(LocationManager locationManager) {
    // 构建位置查询条件
    Criteria criteria = new Criteria();
    // 查询精度:高
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    // 速度
    criteria.setSpeedRequired(false);
    // 是否查询海拨:否
    criteria.setAltitudeRequired(false);
    // 是否查询方位角:否
    criteria.setBearingRequired(false);
    // 电量要求:低
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    // 返回最合适的符合条件的provider,第2个参数为true说明,如果只有一个provider是有效的,则返回当前provider
    return locationManager.getBestProvider(criteria, true);
}
 
Example 9
Source File: OrientationManager.java    From PTVGlass with MIT License 5 votes vote down vote up
/**
 * Initializes a new instance of {@code OrientationManager}, using the specified context to
 * access system services.
 */
public OrientationManager(SensorManager sensorManager, LocationManager locationManager) {
    mRotationMatrix = new float[16];
    mOrientation = new float[9];
    mSensorManager = sensorManager;
    mLocationManager = locationManager;
    mListeners = new LinkedHashSet<OnChangedListener>();

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setBearingRequired(false);
    criteria.setSpeedRequired(false);

    mLocationProvider = mLocationManager.getBestProvider(criteria, true /* enabledOnly */);
}
 
Example 10
Source File: OrientationManager.java    From PTVGlass with MIT License 5 votes vote down vote up
/**
 * Starts tracking the user's location and orientation. After calling this method, any
 * {@link OnChangedListener}s added to this object will be notified of these events.
 */
public void start() {
    if (!mTracking) {
        mSensorManager.registerListener(mSensorListener,
                mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR),
                SensorManager.SENSOR_DELAY_UI);

        // The rotation vector sensor doesn't give us accuracy updates, so we observe the
        // magnetic field sensor solely for those.
        mSensorManager.registerListener(mSensorListener,
                mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
                SensorManager.SENSOR_DELAY_UI);

        Location lastLocation = mLocationManager
                .getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
        if (lastLocation != null) {
            long locationAge = lastLocation.getTime() - System.currentTimeMillis();
            if (locationAge < MAX_LOCATION_AGE_MILLIS) {
                mLocation = lastLocation;
                updateGeomagneticField();
            }
        }

        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setBearingRequired(false);
        criteria.setSpeedRequired(false);

        List<String> providers =
                mLocationManager.getProviders(criteria, true /* enabledOnly */);
        for (String provider : providers) {
            mLocationManager.requestLocationUpdates(provider,
                    MILLIS_BETWEEN_LOCATIONS, METERS_BETWEEN_LOCATIONS, mLocationListener,
                    Looper.getMainLooper());
        }

        mTracking = true;
    }
}
 
Example 11
Source File: OrientationManager.java    From SpeedHud with Apache License 2.0 5 votes vote down vote up
/**
 * Starts tracking the user's location and orientation. After calling this method, any
 * {@link OnChangedListener}s added to this object will be notified of these events.
 */
public void start() {
    if (!mTracking) {
        mSensorManager.registerListener(mSensorListener,
                mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR),
                SensorManager.SENSOR_DELAY_UI);

        // The rotation vector sensor doesn't give us accuracy updates, so we observe the
        // magnetic field sensor solely for those.
        mSensorManager.registerListener(mSensorListener,
                mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
                SensorManager.SENSOR_DELAY_UI);

        Location lastLocation = mLocationManager
                .getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
        if (lastLocation != null) {
            long locationAge = lastLocation.getTime() - System.currentTimeMillis();
            if (locationAge < MAX_LOCATION_AGE_MILLIS) {
                mLocation = lastLocation;
                updateGeomagneticField();
            }
        }

        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setBearingRequired(false);
        criteria.setSpeedRequired(false);

        List<String> providers =
                mLocationManager.getProviders(criteria, true /* enabledOnly */);
        for (String provider : providers) {
            mLocationManager.requestLocationUpdates(provider,                        MILLIS_BETWEEN_LOCATIONS, METERS_BETWEEN_LOCATIONS, mLocationListener,
            Looper.getMainLooper());
        }

        mTracking = true;
    }
}
 
Example 12
Source File: LocationUtils.java    From iot-starter-for-android with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Helper method to create a criteria for location change listener
 *
 * @return criteria constructed for the listener
 */
private Criteria getCriteria() {
    Criteria criteria = new Criteria();
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(true);
    criteria.setCostAllowed(true);
    criteria.setSpeedRequired(true);
    return criteria;
}
 
Example 13
Source File: AndroidLocationManager.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private String findProvider(boolean includeNetwork) {
    String providerName = null;
    Criteria criteria = new Criteria();
    criteria.setSpeedRequired(true);
    criteria.setAltitudeRequired(true);

    LocationProvider provider;
    boolean enabled;

    if (includeNetwork) {
        provider = locationManager.getProvider(LocationManager.NETWORK_PROVIDER);
        enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        if (provider != null && enabled) {
            providerName = provider.getName();
        } else {
            providerName = locationManager.getBestProvider(criteria, true);
        }
    }

    if (providerName == null) {
        // If GPS provider, then create and start GPS listener
        provider = locationManager.getProvider(LocationManager.GPS_PROVIDER);
        enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        if (provider != null && enabled) {
            providerName = provider.getName();
        }
    }
    return providerName;
}
 
Example 14
Source File: BackgroundLocationUpdateService.java    From cordova-background-geolocation-services with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Log.i(TAG, "OnCreate");

    toneGenerator           = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
    notificationManager     = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
    connectivityManager     = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

    // Location Update PI
    Intent locationUpdateIntent = new Intent(Constants.LOCATION_UPDATE);
    locationUpdatePI = PendingIntent.getBroadcast(this, 9001, locationUpdateIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    registerReceiver(locationUpdateReceiver, new IntentFilter(Constants.LOCATION_UPDATE));

    Intent detectedActivitiesIntent = new Intent(Constants.DETECTED_ACTIVITY_UPDATE);
    detectedActivitiesPI = PendingIntent.getBroadcast(this, 9002, detectedActivitiesIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    registerReceiver(detectedActivitiesReceiver, new IntentFilter(Constants.DETECTED_ACTIVITY_UPDATE));

    // Receivers for start/stop recording
    registerReceiver(startRecordingReceiver, new IntentFilter(Constants.START_RECORDING));
    registerReceiver(stopRecordingReceiver, new IntentFilter(Constants.STOP_RECORDING));
    registerReceiver(startAggressiveReceiver, new IntentFilter(Constants.CHANGE_AGGRESSIVE));

    // Location criteria
    criteria = new Criteria();
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setSpeedRequired(true);
    criteria.setCostAllowed(true);
}
 
Example 15
Source File: LocationUtils.java    From Easer with GNU General Public License v3.0 5 votes vote down vote up
static Criteria getCriteria() {
    Criteria criteria = new Criteria();
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(false);
    criteria.setSpeedRequired(false);
    criteria.setAccuracy(Criteria.NO_REQUIREMENT);
    return criteria;
}
 
Example 16
Source File: DistanceFilterLocationProvider.java    From background-geolocation-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
    alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);

    // Stop-detection PI
    stationaryAlarmPI = PendingIntent.getBroadcast(mContext, 0, new Intent(STATIONARY_ALARM_ACTION), 0);
    registerReceiver(stationaryAlarmReceiver, new IntentFilter(STATIONARY_ALARM_ACTION));

    // Stationary region PI
    stationaryRegionPI = PendingIntent.getBroadcast(mContext, 0, new Intent(STATIONARY_REGION_ACTION), PendingIntent.FLAG_CANCEL_CURRENT);
    registerReceiver(stationaryRegionReceiver, new IntentFilter(STATIONARY_REGION_ACTION));

    // Stationary location monitor PI
    stationaryLocationPollingPI = PendingIntent.getBroadcast(mContext, 0, new Intent(STATIONARY_LOCATION_MONITOR_ACTION), 0);
    registerReceiver(stationaryLocationMonitorReceiver, new IntentFilter(STATIONARY_LOCATION_MONITOR_ACTION));

    // One-shot PI (TODO currently unused)
    singleUpdatePI = PendingIntent.getBroadcast(mContext, 0, new Intent(SINGLE_LOCATION_UPDATE_ACTION), PendingIntent.FLAG_CANCEL_CURRENT);
    registerReceiver(singleUpdateReceiver, new IntentFilter(SINGLE_LOCATION_UPDATE_ACTION));

    // Location criteria
    criteria = new Criteria();
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setSpeedRequired(true);
    criteria.setCostAllowed(true);
}
 
Example 17
Source File: MovementSpeedService.java    From privacy-friendly-pedometer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return Name of location provider
 */
private String getProviderName() {
    Criteria criteria = new Criteria();
    criteria.setSpeedRequired(true);
    return mLocationManager.getBestProvider(criteria, true);
}