com.google.android.gms.location.LocationRequest Java Examples

The following examples show how to use com.google.android.gms.location.LocationRequest. 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: WhereAmIActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_where_am_i);

  mTextView = findViewById(R.id.myLocationText);

  GoogleApiAvailability availability = GoogleApiAvailability.getInstance();

  int result = availability.isGooglePlayServicesAvailable(this);
  if (result != ConnectionResult.SUCCESS) {
    if (!availability.isUserResolvableError(result)) {
      Toast.makeText(this, ERROR_MSG, Toast.LENGTH_LONG).show();
    }
  }

  mLocationRequest = new LocationRequest()
                       .setInterval(5000)
                       .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
 
Example #2
Source File: LocationRepository.java    From android with Apache License 2.0 6 votes vote down vote up
public Observable<Location> getLocation(boolean force) {
    if (shouldRequestNewLocation() || force) {
        LocationRequest request = LocationRequest.create()
                .setNumUpdates(1);

        return getLocation(request)
                .timeout(mRequestTimeout, TimeUnit.MILLISECONDS)
                .onErrorResumeNext(new Func1<Throwable, Observable<? extends Location>>() {
                    @Override
                    public Observable<? extends Location> call(Throwable e) {
                        if (e instanceof TimeoutException && mLastLocation == null) {
                            return Observable.error(new LocationTimeoutException());
                        } else if (mLastLocation == null) {
                            return Observable.error(e);
                        } else {
                            return Observable.just(mLastLocation);
                        }
                    }
                })
                .first();
    } else {
        return Observable.just(mLastLocation);
    }
}
 
Example #3
Source File: BasePlatformCreate.java    From indigenous-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initiate the location libraries and services.
 */
private void initLocationLibraries() {
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    mSettingsClient = LocationServices.getSettingsClient(this);

    mLocationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            super.onLocationResult(locationResult);
            // location is received
            mCurrentLocation = locationResult.getLastLocation();
            updateLocationUI();
        }
    };

    mRequestingLocationUpdates = false;

    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
    mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
    builder.addLocationRequest(mLocationRequest);
    mLocationSettingsRequest = builder.build();
}
 
Example #4
Source File: RunActivity.java    From SEAL-Demo with MIT License 6 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    MapUtil.changeMapStyle(TAG, mMap, this);
    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(UPDATE_TIME);
    mLocationRequest.setFastestInterval(UPDATE_TIME);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.ACCESS_FINE_LOCATION)
                == PackageManager.PERMISSION_GRANTED) {
            //Location Permission already granted
            mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
            mMap.setMyLocationEnabled(true);
        }
    } else {
        mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
        mMap.setMyLocationEnabled(true);
    }
}
 
Example #5
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 #6
Source File: RunService.java    From SEAL-Demo with MIT License 6 votes vote down vote up
private void startService() {
    startForeground(FOREGROUND_ID, buildForegroundNotification());
    mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME);
    mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME);
    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(UPDATE_TIME);
    mLocationRequest.setFastestInterval(UPDATE_TIME);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.ACCESS_FINE_LOCATION)
                == PackageManager.PERMISSION_GRANTED) {
            //Location Permission already granted
            mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
        }
    } else {
        mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
    }
    timer.scheduleAtFixedRate(new mainTask(), 0, 1000);
}
 
Example #7
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 #8
Source File: ConversationActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
    try {
        Location mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
        if (mCurrentLocation == null) {
            Toast.makeText(this, R.string.waiting_for_current_location, Toast.LENGTH_SHORT).show();
            locationRequest = new LocationRequest();
            locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
            locationRequest.setInterval(UPDATE_INTERVAL);
            locationRequest.setFastestInterval(FASTEST_INTERVAL);
            LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
        }
        if (mCurrentLocation != null && conversation != null) {
            conversation.attachLocation(mCurrentLocation);
        }
    } catch (Exception e) {
    }

}
 
Example #9
Source File: GoogleLocationEngineImplAdditionalTest.java    From mapbox-events-android with MIT License 6 votes vote down vote up
@Before
public void setUp() {
  location = mock(Location.class);
  when(location.getLatitude()).thenReturn(1.0);
  when(location.getLongitude()).thenReturn(2.0);
  locationList.clear();
  locationList.add(location);
  fusedLocationProviderClient = mock(FusedLocationProviderClient.class);
  mockTask = mock(Task.class);
  mockLocationTask = mock(Task.class);
  when(fusedLocationProviderClient.getLastLocation()).thenReturn(mockLocationTask);
  when(fusedLocationProviderClient
    .requestLocationUpdates(any(LocationRequest.class), any(LocationCallback.class), any(Looper.class)))
    .thenAnswer(new Answer<Task<Void>>() {
      @Override
      public Task<Void> answer(InvocationOnMock invocation) {
        LocationCallback listener = (LocationCallback) invocation.getArguments()[1];
        listener.onLocationResult(LocationResult.create(locationList));
        return mockTask;
      }
    });

  engine = new LocationEngineProxy<>(new GoogleLocationEngineImpl(fusedLocationProviderClient));
}
 
Example #10
Source File: MainActivity.java    From location-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the location request. Android has two location request settings:
 * {@code ACCESS_COARSE_LOCATION} and {@code ACCESS_FINE_LOCATION}. These settings control
 * the accuracy of the current location. This sample uses ACCESS_FINE_LOCATION, as defined in
 * the AndroidManifest.xml.
 * <p/>
 * When the ACCESS_FINE_LOCATION setting is specified, combined with a fast update
 * interval (5 seconds), the Fused Location Provider API returns location updates that are
 * accurate to within a few feet.
 * <p/>
 * These settings are appropriate for mapping applications that show real-time location
 * updates.
 */
private void createLocationRequest() {
    mLocationRequest = new LocationRequest();

    // Sets the desired interval for active location updates. This interval is
    // inexact. You may not receive updates at all if no location sources are available, or
    // you may receive them slower than requested. You may also receive updates faster than
    // requested if other applications are requesting location at a faster interval.
    mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);

    // Sets the fastest rate for active location updates. This interval is exact, and your
    // application will never receive updates faster than this value.
    mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);

    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
 
Example #11
Source File: EasyWayLocation.java    From EasyWayLocation with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a new instance
 * @param context Context reference to get the system service from
 * @param locationRequest
 * location request
 * @param requireLastLocation require last location or not

 */
public EasyWayLocation(Context context, final LocationRequest locationRequest, final boolean requireLastLocation,final Listener listener) {
   // mLocationManager = (LocationManager) context.getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
    this.context = context;
    this.mListener = listener;
    fusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
    if (locationRequest != null){
        this.locationRequest = locationRequest;
    }else {
        this.locationRequest = new LocationRequest();
        this.locationRequest.setInterval(10000);
       // locationRequest.setSmallestDisplacement(10F);
        this.locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    }
    this.mRequireLastLocation = requireLastLocation;
    if (mRequireLastLocation) {
        getCachedPosition();
        //cachePosition();
    }
}
 
Example #12
Source File: ActivityRecognitionLocationProvider.java    From background-geolocation-android with Apache License 2.0 6 votes vote down vote up
public void startTracking() {
    if (isTracking) { return; }

    Integer priority = translateDesiredAccuracy(mConfig.getDesiredAccuracy());
    LocationRequest locationRequest = LocationRequest.create()
            .setPriority(priority) // this.accuracy
            .setFastestInterval(mConfig.getFastestInterval())
            .setInterval(mConfig.getInterval());
    // .setSmallestDisplacement(mConfig.getStationaryRadius());
    try {
        LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
        isTracking = true;
        logger.debug("Start tracking with priority={} fastestInterval={} interval={} activitiesInterval={} stopOnStillActivity={}", priority, mConfig.getFastestInterval(), mConfig.getInterval(), mConfig.getActivitiesInterval(), mConfig.getStopOnStillActivity());
    } catch (SecurityException e) {
        logger.error("Security exception: {}", e.getMessage());
        this.handleSecurityException(e);
    }
}
 
Example #13
Source File: GoogleLocationUpdatesProvider.java    From PrivacyStreams with Apache License 2.0 6 votes vote down vote up
private void startLocationUpdate() {
    long fastInterval = interval / 2;

    LocationRequest mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(interval);
    mLocationRequest.setFastestInterval(fastInterval);

    if (Geolocation.LEVEL_EXACT.equals(this.level))
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    else if (Geolocation.LEVEL_BUILDING.equals(this.level))
        mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    else
        mLocationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);

    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
 
Example #14
Source File: LocationService.java    From redalert-android with Apache License 2.0 6 votes vote down vote up
void initializeLocationPolling() {
    // Create new request
    mLocationRequest = LocationRequest.create();

    // Low battery mode
    mLocationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);

    // Set update intervals
    mLocationRequest.setInterval(LocationLogic.getUpdateIntervalMilliseconds(this));

    // Create new location receive client
    mClient = new GoogleApiClient.Builder(this)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
}
 
Example #15
Source File: CustomLocationTrackingActivity.java    From android-map-sdk with Apache License 2.0 6 votes vote down vote up
private void enableLocation() {
    new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
            @SuppressLint("MissingPermission")
            @Override
            public void onConnected(@Nullable Bundle bundle) {
                LocationRequest locationRequest = new LocationRequest();
                locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
                locationRequest.setInterval(LOCATION_REQUEST_INTERVAL);
                locationRequest.setFastestInterval(LOCATION_REQUEST_INTERVAL);

                LocationServices.getFusedLocationProviderClient(CustomLocationTrackingActivity.this)
                    .requestLocationUpdates(locationRequest, locationCallback, null);
                locationEnabled = true;
                waiting = true;
            }

            @Override
            public void onConnectionSuspended(int i) {
            }
        })
        .addApi(LocationServices.API)
        .build()
        .connect();
}
 
Example #16
Source File: LocationUpdateReceiver.java    From home-assistant-Android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onConnected(@Nullable Bundle bundle) {
    if (ActivityCompat.checkSelfPermission(apiClient.getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        if (prefs.getBoolean(Common.PREF_ENABLE_LOCATION_TRACKING, false) && !TextUtils.isEmpty(prefs.getString(Common.PREF_LOCATION_DEVICE_NAME, null))) {
            LocationRequest locationRequest = new LocationRequest();
            locationRequest.setInterval(prefs.getInt(Common.PREF_LOCATION_UPDATE_INTERVAL, 10) * 60 * 1000);
            locationRequest.setFastestInterval(5 * 60 * 1000);
            locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
            LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, getPendingIntent(apiClient.getContext()));
            Log.d(TAG, "Started requesting location updates");
        } else {
            LocationServices.FusedLocationApi.removeLocationUpdates(apiClient, getPendingIntent(apiClient.getContext()));
            Log.d(TAG, "Stopped requesting location updates");
        }
    }
    apiClient.disconnect();
}
 
Example #17
Source File: MainActivity.java    From location-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the location request. Android has two location request settings:
 * {@code ACCESS_COARSE_LOCATION} and {@code ACCESS_FINE_LOCATION}. These settings control
 * the accuracy of the current location. This sample uses ACCESS_FINE_LOCATION, as defined in
 * the AndroidManifest.xml.
 * <p/>
 * When the ACCESS_FINE_LOCATION setting is specified, combined with a fast update
 * interval (5 seconds), the Fused Location Provider API returns location updates that are
 * accurate to within a few feet.
 * <p/>
 * These settings are appropriate for mapping applications that show real-time location
 * updates.
 */
private void createLocationRequest() {
    mLocationRequest = new LocationRequest();

    // Sets the desired interval for active location updates. This interval is
    // inexact. You may not receive updates at all if no location sources are available, or
    // you may receive them slower than requested. You may also receive updates faster than
    // requested if other applications are requesting location at a faster interval.
    // Note: apps running on "O" devices (regardless of targetSdkVersion) may receive updates
    // less frequently than this interval when the app is no longer in the foreground.
    mLocationRequest.setInterval(UPDATE_INTERVAL);

    // Sets the fastest rate for active location updates. This interval is exact, and your
    // application will never receive updates faster than this value.
    mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL);

    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    // Sets the maximum time when batched location updates are delivered. Updates may be
    // delivered sooner than this interval.
    mLocationRequest.setMaxWaitTime(MAX_WAIT_TIME);
}
 
Example #18
Source File: LocationActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
private void startTrackingLocation() {
  if (
    ActivityCompat
      .checkSelfPermission(this, ACCESS_FINE_LOCATION) == PERMISSION_GRANTED ||
      ActivityCompat
        .checkSelfPermission(this, ACCESS_COARSE_LOCATION) == PERMISSION_GRANTED) {

    FusedLocationProviderClient locationClient = LocationServices.getFusedLocationProviderClient(this);
    LocationRequest request =
      new LocationRequest()
        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
        .setInterval(5000); // Update every 5 seconds.

    locationClient.requestLocationUpdates(request, mLocationCallback, null);
  }
}
 
Example #19
Source File: MapLoadFragment.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnected(Bundle connectionHint) {
    LocationRequest mLocationRequest = createLocationRequest();
    if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        ActivityCompat.requestPermissions(
                getActivity(),
                new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_NETWORK_STATE, Manifest.permission.LOCATION_HARDWARE, Manifest.permission_group.LOCATION},
                PERMISSION_LOCATION_REQUEST_CODE);
        return;
    }
    LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient, mLocationRequest, this);

    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
            mGoogleApiClient);
}
 
Example #20
Source File: MainActivity.java    From android-rxlocationsettings with Apache License 2.0 5 votes vote down vote up
private void ensureLocationSettings() {
  LocationSettingsRequest locationSettingsRequest = new LocationSettingsRequest.Builder()
      .addLocationRequest(LocationRequest.create().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY))
      .build();
  RxLocationSettings.with(this).ensure(locationSettingsRequest)
      .subscribe(new Action1<Boolean>() {
        @Override
        public void call(Boolean enabled) {
          Toast.makeText(MainActivity.this, enabled ? "Enabled" : "Failed", Toast.LENGTH_LONG).show();
        }
      });
}
 
Example #21
Source File: ShareLocationActivity.java    From ShareLocationPlugin with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
	mLocationRequest = LocationRequest.create();
       mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
       mLocationRequest.setInterval(1000);

       LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
 
Example #22
Source File: LocationAccuracyTests.java    From openlocate-android with MIT License 5 votes vote down vote up
@Test
public void testLocationRequestAccuracy() {
    Assert.assertEquals(LocationAccuracy.HIGH.getLocationRequestAccuracy(), LocationRequest.PRIORITY_HIGH_ACCURACY);
    Assert.assertEquals(LocationAccuracy.MEDIUM.getLocationRequestAccuracy(), LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    Assert.assertEquals(LocationAccuracy.LOW.getLocationRequestAccuracy(), LocationRequest.PRIORITY_LOW_POWER);
    Assert.assertEquals(LocationAccuracy.NO_POWER.getLocationRequestAccuracy(), LocationRequest.PRIORITY_NO_POWER);
}
 
Example #23
Source File: MapsActivity.java    From Krishi-Seva with MIT License 5 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(1000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
    }
}
 
Example #24
Source File: BackgroundLocationService.java    From android-location-service with Apache License 2.0 5 votes vote down vote up
public void requestUpdates(LocationRequest locationRequest) {
    if (isLocationServicesConnected()) {
        if( DEBUG ) {
            Log.d(TAG, "Requesting updates for [" + locationRequest + "]");
        }
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this);
        Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
        if (location != null) {
            onLocationChanged(location);
        }
    }
}
 
Example #25
Source File: LocationUpdatesService.java    From location-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the location request parameters.
 */
private void createLocationRequest() {
    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
    mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
 
Example #26
Source File: LocationRequestUtils.java    From android-location-service with Apache License 2.0 5 votes vote down vote up
public static LocationRequest byDisplacement(float smallestDisplacement, long intervalMillis) {
    return LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(intervalMillis)
            .setFastestInterval(intervalMillis)
            .setSmallestDisplacement(smallestDisplacement);
}
 
Example #27
Source File: WearableLocationService.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
private static LocationRequestInternal readLocationRequest(DataMap dataMap, Context context) {
    LocationRequestInternal request = new LocationRequestInternal();
    request.triggerUpdate = true;
    request.request = new LocationRequest();
    request.clients = Collections.emptyList();

    if (dataMap.containsKey("PRIORITY"))
        request.request.setPriority(dataMap.getInt("PRIORITY", 0));
    if (dataMap.containsKey("INTERVAL_MS"))
        request.request.setInterval(dataMap.getLong("INTERVAL_MS", 0));
    if (dataMap.containsKey("FASTEST_INTERVAL_MS"))
        request.request.setFastestInterval(dataMap.getLong("FASTEST_INTERVAL_MS", 0));
    //if (dataMap.containsKey("MAX_WAIT_TIME_MS"))
    if (dataMap.containsKey("SMALLEST_DISPLACEMENT_METERS"))
        request.request.setSmallestDisplacement(dataMap.getFloat("SMALLEST_DISPLACEMENT_METERS", 0));
    if (dataMap.containsKey("NUM_UPDATES"))
        request.request.setNumUpdates(dataMap.getInt("NUM_UPDATES", 0));
    if (dataMap.containsKey("EXPIRATION_DURATION_MS"))
        request.request.setExpirationDuration(dataMap.getLong("EXPIRATION_DURATION_MS", 0));
    if (dataMap.containsKey("TAG"))
        request.tag = dataMap.getString("TAG");
    if (dataMap.containsKey("CLIENTS_PACKAGE_ARRAY")) {
        String[] packages = dataMap.getStringArray("CLIENTS_PACKAGE_ARRAY");
        if (packages != null) {
            request.clients = new ArrayList<ClientIdentity>();
            for (String packageName : packages) {
                request.clients.add(generateClientIdentity(packageName, context));
            }
        }
    }

    return request;
}
 
Example #28
Source File: EasyLocationDelegate.java    From Android-EasyLocation with Apache License 2.0 5 votes vote down vote up
private void startLocationBGService(LocationRequest locationRequest, long fallBackToLastLocationTime) {
    if (!isLocationEnabled())
        showLocationServicesRequireDialog();
    else {
        Intent intent = new Intent(activity, LocationBgService.class);
        intent.setAction(AppConstants.ACTION_LOCATION_FETCH_START);
        intent.putExtra(IntentKey.LOCATION_REQUEST, locationRequest);
        intent.putExtra(IntentKey.LOCATION_FETCH_MODE, mLocationFetchMode);
        intent.putExtra(IntentKey.FALLBACK_TO_LAST_LOCATION_TIME, fallBackToLastLocationTime);
        activity.startService(intent);
    }
}
 
Example #29
Source File: LocationProvider.java    From LocationAware with Apache License 2.0 5 votes vote down vote up
@NonNull private LocationRequest getLocationRequest() {
  LocationRequest locationRequest = new LocationRequest();
  locationRequest.setInterval(LOCATION_UPDATE_INTERVAL);
  locationRequest.setFastestInterval(LOCATION_UPDATE_FASTEST_INTERVAL);
  locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
  return locationRequest;
}
 
Example #30
Source File: FusedLocationModule.java    From react-native-fused-location with MIT License 5 votes vote down vote up
private LocationRequest buildLR() {
    LocationRequest request = new LocationRequest();
    request.setPriority(mLocationPriority);
    request.setInterval(mLocationInterval);
    request.setFastestInterval(mLocationFastestInterval);
    request.setSmallestDisplacement(mSmallestDisplacement);
    return request;
}