Java Code Examples for com.google.android.gms.location.LocationRequest#setMaxWaitTime()

The following examples show how to use com.google.android.gms.location.LocationRequest#setMaxWaitTime() . 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: 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 2
Source File: CalculationModulesArrayList.java    From GNSS_Compare with Apache License 2.0 5 votes vote down vote up
public CalculationModulesArrayList(){
    gnssCallback = new GnssMeasurementsEvent.Callback() {
        @Override
        public void onGnssMeasurementsReceived(GnssMeasurementsEvent eventArgs) {
        super.onGnssMeasurementsReceived(eventArgs);

        Log.d(TAG, "onGnssMeasurementsReceived: invoked!");

        for (CalculationModule calculationModule : CalculationModulesArrayList.this)
            calculationModule.updateMeasurements(eventArgs);

        if(mPoseUpdatedListener !=null)
            mPoseUpdatedListener.onPoseUpdated();
        }
    };

    locationRequest = new LocationRequest();

    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setMaxWaitTime(500);
    locationRequest.setInterval(1000);
    locationRequest.setFastestInterval(100);

    locationCallback = new LocationCallback(){
        @Override
        public void onLocationResult(LocationResult locationResult) {

        final Location lastLocation = locationResult.getLocations().get(locationResult.getLocations().size()-1);

        if(lastLocation != null) {
            synchronized (this) {
                for (CalculationModule calculationModule : CalculationModulesArrayList.this)
                    calculationModule.updateLocationFromGoogleServices(lastLocation);

            }
        }
        }
    };
}
 
Example 3
Source File: OpenLocateHelper.java    From openlocate-android with MIT License 5 votes vote down vote up
private void buildLocationRequest() {
    long locationUpdateInterval = configuration.getLocationUpdateInterval() * 1000;
    long locationTransmissionInterval = configuration.getTransmissionInterval() * 1000;
    int locationAccuracy = configuration.getLocationAccuracy().getLocationRequestAccuracy();

    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(locationUpdateInterval);
    mLocationRequest.setFastestInterval(locationUpdateInterval / 2);
    mLocationRequest.setMaxWaitTime(Math.max(locationUpdateInterval * 2, (int)(locationTransmissionInterval * 0.85 / 3)));
    mLocationRequest.setPriority(locationAccuracy);
}
 
Example 4
Source File: GoogleLocationEngineImpl.java    From mapbox-events-android with MIT License 5 votes vote down vote up
private static LocationRequest toGMSLocationRequest(LocationEngineRequest request) {
  LocationRequest locationRequest = new LocationRequest();
  locationRequest.setInterval(request.getInterval());
  locationRequest.setFastestInterval(request.getFastestInterval());
  locationRequest.setSmallestDisplacement(request.getDisplacement());
  locationRequest.setMaxWaitTime(request.getMaxWaitTime());
  locationRequest.setPriority(toGMSLocationPriority(request.getPriority()));
  return locationRequest;
}
 
Example 5
Source File: MainActivity.java    From background-location-updates-android-o with Apache License 2.0 5 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();

    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 6
Source File: MainActivity.java    From GNSS_Compare with Apache License 2.0 4 votes vote down vote up
/**
 * Registers GNSS measurement event manager callback.
 */
private void registerLocationManager() {

    mLocationManager = (LocationManager) getApplicationContext().getSystemService(LOCATION_SERVICE);
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);

    gnssCallback = new GnssMeasurementsEvent.Callback() {
        @Override
        public void onGnssMeasurementsReceived(GnssMeasurementsEvent eventArgs) {
            super.onGnssMeasurementsReceived(eventArgs);

            Log.d(TAG, "onGnssMeasurementsReceived (MainActivity): invoked!");

            if (rawMeasurementsLogger.isStarted())
                rawMeasurementsLogger.onGnssMeasurementsReceived(eventArgs);
        }
    };

    final LocationRequest locationRequest = new LocationRequest();

    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setMaxWaitTime(500);
    locationRequest.setInterval(1000);
    locationRequest.setFastestInterval(100);

    locationCallback = new LocationCallback(){
        @Override
        public void onLocationResult(LocationResult locationResult) {

            final Location lastLocation = locationResult.getLocations().get(locationResult.getLocations().size()-1);

            if(lastLocation != null) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        for(DataViewer dataViewer : mPagerAdapter.getViewers()) {
                            dataViewer.onLocationFromGoogleServicesResult(lastLocation);
                        }
                    }
                });

                Log.i(TAG, "locationFromGoogleServices: New location (phone): "
                        + lastLocation.getLatitude() + ", "
                        + lastLocation.getLongitude() + ", "
                        + lastLocation.getAltitude());

            }
        }
    };

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
            || ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {

        mFusedLocationClient.requestLocationUpdates(
                locationRequest,
                locationCallback,
                null);

        mLocationManager.registerGnssMeasurementsCallback(
                gnssCallback);


    }
}