Java Code Examples for com.google.android.gms.location.LocationRequest#setFastestInterval()
The following examples show how to use
com.google.android.gms.location.LocationRequest#setFastestInterval() .
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 |
/** * 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 2
Source File: MainActivity.java From location-samples with Apache License 2.0 | 6 votes |
/** * 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 3
Source File: CoordinatesView.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void startRequestingLocation() { LocationRequest locationRequest = new LocationRequest(); locationRequest.setInterval(5000); locationRequest.setFastestInterval(1000); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationCallback = new LocationCallback() { @Override public void onLocationResult(LocationResult locationResult) { if (locationResult != null) { Double latitude = locationResult.getLocations().get(0).getLatitude(); Double longitude = locationResult.getLocations().get(0).getLongitude(); updateLocation(GeometryHelper.createPointGeometry(longitude, latitude)); mFusedLocationClient.removeLocationUpdates(locationCallback); } } }; if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions((ActivityGlobalAbstract) getContext(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, ACCESS_LOCATION_PERMISSION_REQUEST); } else mFusedLocationClient.requestLocationUpdates(locationRequest, locationCallback, null); }
Example 4
Source File: LocationUpdatesService.java From location-samples with Apache License 2.0 | 5 votes |
/** * 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 5
Source File: LocationTracker.java From SampleApp with Apache License 2.0 | 5 votes |
/** * Creating location request object */ private void createLocationRequest() { mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(UPDATE_INTERVAL); mLocationRequest.setFastestInterval(FATEST_INTERVAL); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setSmallestDisplacement(DISPLACEMENT); }
Example 6
Source File: GoogleLocationEngineImpl.java From mapbox-events-android with MIT License | 5 votes |
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 7
Source File: MainActivity.java From background-location-updates-android-o with Apache License 2.0 | 5 votes |
/** * 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 8
Source File: MapsActivity.java From Krishi-Seva with MIT License | 5 votes |
@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 9
Source File: MapsActivity.java From journaldev with MIT License | 5 votes |
protected void startLocationUpdates() { mLocationRequest = new LocationRequest(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(UPDATE_INTERVAL); mLocationRequest.setFastestInterval(FASTEST_INTERVAL); if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(getApplicationContext(), "Enable Permissions", Toast.LENGTH_LONG).show(); } LocationServices.FusedLocationApi.requestLocationUpdates( mGoogleApiClient, mLocationRequest, this); }
Example 10
Source File: LocationUpdatesBroadcastReceiver.java From background_location_updates with Apache License 2.0 | 5 votes |
@SuppressLint("MissingPermission") public static void startTrackingBroadcastBased(Context context, int requestInterval) { FusedLocationProviderClient client = LocationServices.getFusedLocationProviderClient(context); LocationRequest request = new LocationRequest(); request.setInterval(requestInterval); request.setFastestInterval(requestInterval); request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); client.requestLocationUpdates(request, LocationUpdatesBroadcastReceiver.getPendingIntent(context)); }
Example 11
Source File: AndroidLocationProvider.java From BLE-Indoor-Positioning with Apache License 2.0 | 5 votes |
private LocationRequest createHighAccuracyLocationRequest() { LocationRequest locationRequest = new LocationRequest(); locationRequest.setInterval(TimeUnit.SECONDS.toMillis(3)); locationRequest.setFastestInterval(TimeUnit.SECONDS.toMillis(1)); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); return locationRequest; }
Example 12
Source File: MainActivity.java From OpenCircle with GNU General Public License v3.0 | 5 votes |
protected LocationRequest makeLocationRequest() { LocationRequest mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(0); mLocationRequest.setFastestInterval(0); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); return mLocationRequest; }
Example 13
Source File: MobicomLocationActivity.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onConnected(Bundle bundle) { try { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, 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. return; } 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_BALANCED_POWER_ACCURACY); locationRequest.setInterval(UPDATE_INTERVAL); locationRequest.setFastestInterval(FASTEST_INTERVAL); LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this); } if (mCurrentLocation != null) { mapFragment.getMapAsync(this); } } catch (Exception e) { e.printStackTrace(); } }
Example 14
Source File: MapsActivity.java From q-municate-android with Apache License 2.0 | 5 votes |
private void buildRequestLocation() { if (checkPermission()) { return; } LocationRequest locationRequest = new LocationRequest(); // in seconds locationRequest.setInterval(5000); locationRequest.setFastestInterval(3000); locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); //locationRequest.setSmallestDisplacement(0.1F); //1/10 meter LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this); }
Example 15
Source File: Location.java From UberClone with MIT License | 4 votes |
private void inicializeLocationRequest(){ locationRequest=new LocationRequest(); locationRequest.setInterval(10000); locationRequest.setFastestInterval(3000); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); }
Example 16
Source File: Location.java From UberClone with MIT License | 4 votes |
private void inicializeLocationRequest(){ locationRequest=new LocationRequest(); locationRequest.setInterval(10000); locationRequest.setFastestInterval(3000); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); }
Example 17
Source File: ControllerActivity.java From Bluefruit_LE_Connect_Android with MIT License | 4 votes |
private void registerEnabledSensorListeners(boolean register) { // Accelerometer if (register && (mSensorData[kSensorType_Accelerometer].enabled || mSensorData[kSensorType_Quaternion].enabled)) { mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); } else { mSensorManager.unregisterListener(this, mAccelerometer); } // Gyroscope if (register && mSensorData[kSensorType_Gyroscope].enabled) { mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_NORMAL); } else { mSensorManager.unregisterListener(this, mGyroscope); } // Magnetometer if (register && (mSensorData[kSensorType_Magnetometer].enabled || mSensorData[kSensorType_Quaternion].enabled)) { if (mMagnetometer == null) { new AlertDialog.Builder(this) .setMessage(getString(R.string.controller_magnetometermissing)) .setPositiveButton(android.R.string.ok, null) .show(); } else { mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_NORMAL); } } else { mSensorManager.unregisterListener(this, mMagnetometer); } // Location if (mGoogleApiClient.isConnected()) { if (register && mSensorData[kSensorType_Location].enabled) { LocationRequest locationRequest = new LocationRequest(); locationRequest.setInterval(2000); locationRequest.setFastestInterval(500); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // Location updates should have already been granted to scan for bluetooth peripherals, so we dont ask for them again try { LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this); } catch (SecurityException e) { Log.e(TAG, "Security exception requesting location updates: " + e); } } else { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this); } } }
Example 18
Source File: NearbyLocationActivity.java From FaceT with Mozilla Public License 2.0 | 4 votes |
@Override public void onConnected(Bundle connectionHint) { Log.d("MYTAG", "GOOGLE API CONNECTED!"); statusCheck(); if (ContextCompat.checkSelfPermission(NearbyLocationActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(1); mLocationRequest.setFastestInterval(1); mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); mLocationRequest.setSmallestDisplacement(0); LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this); mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); Log.d("onConnected", "here!!!!!!!!!!!!"); // if (mLastLocation != null) { // Log.d("onConnected", "not null!!!!!!!!!!!!"); //// LatLng newLocation = new LatLng(mLastLocation.getLongitude(),mLastLocation.getLatitude()); //// mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(newLocation, 9), 3000, null); // initialize=1; // if (LocationServices.FusedLocationApi.getLocationAvailability(mGoogleApiClient).isLocationAvailable()) { //// currentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); //// if (currentLocation != null) { // LatLng myCurrentLocation = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude()); // mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myCurrentLocation, 14), 3000, null); // bottomPanel.setVisibility(View.GONE); //// } // } // // List<Shop> shopWithinRange = new ArrayList<>(); // for (int i = 0; i < shopList.size(); i++) { // LatLng shopLocation = new LatLng(shopList.get(i).getLatitude(), shopList.get(i).getLongitude()); // Marker shopLocationMarker = mMap.addMarker(new MarkerOptions().position(shopLocation) // .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))); // shopLocationMarker.setVisible(false); // Location target = new Location("target"); // target.setLatitude(shopList.get(i).getLatitude()); // target.setLongitude(shopList.get(i).getLongitude()); // Log.d("before_compare_location", "" + mLastLocation.distanceTo(target)); // if (mLastLocation.distanceTo(target) < 3000) { // shopLocationMarker.setVisible(true); // shopWithinRange.add(shopList.get(i)); // } // } //// LatLng myCurrentLatLng = new LatLng(shopWithinRange.get(2).getLatitude(), shopWithinRange.get(2).getLongitude()); //// mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myCurrentLatLng, 13), 4000, null); // } } }
Example 19
Source File: ControllerFragment.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 4 votes |
private void registerEnabledSensorListeners(@NonNull Context context, boolean register) { if (mSensorManager != null) { // Check not null (crash detected when app is resumed and device has been disconnected and onDestroy tries to remove sensor manager listeners) // Accelerometer if (register && (mSensorData[kSensorType_Accelerometer].enabled || mSensorData[kSensorType_Quaternion].enabled)) { mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); } else { mSensorManager.unregisterListener(this, mAccelerometer); } // Gyroscope if (register && mSensorData[kSensorType_Gyroscope].enabled) { mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_NORMAL); } else { mSensorManager.unregisterListener(this, mGyroscope); } // Magnetometer if (register && (mSensorData[kSensorType_Magnetometer].enabled || mSensorData[kSensorType_Quaternion].enabled)) { if (mMagnetometer == null) { new AlertDialog.Builder(context) .setMessage(getString(R.string.controller_magnetometermissing)) .setPositiveButton(android.R.string.ok, null) .show(); mSensorData[kSensorType_Magnetometer].enabled = false; mSensorData[kSensorType_Quaternion].enabled = false; mControllerAdapter.notifySensorChanged(kSensorType_Magnetometer); mControllerAdapter.notifySensorChanged(kSensorType_Quaternion); } else { mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_NORMAL); } } else { mSensorManager.unregisterListener(this, mMagnetometer); } } // Location if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { if (register && mSensorData[kSensorType_Location].enabled) { LocationRequest locationRequest = new LocationRequest(); locationRequest.setInterval(2000); locationRequest.setFastestInterval(500); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // Location updates should have already been granted to scan for bluetooth peripherals, so we don't ask for them again try { mFusedLocationClient.requestLocationUpdates(locationRequest, mLocationCallback, null); } catch (SecurityException e) { Log.e(TAG, "Security exception requesting location updates: " + e); } mControllerAdapter.notifySensorChanged(kSensorType_Location); // Show current values } else { mFusedLocationClient.removeLocationUpdates(mLocationCallback); } } }
Example 20
Source File: MainActivity.java From Android-Fused-location-provider-example with Apache License 2.0 | 4 votes |
protected void createLocationRequest() { mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS); mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); }