Java Code Examples for com.google.android.gms.location.LocationRequest#setPriority()
The following examples show how to use
com.google.android.gms.location.LocationRequest#setPriority() .
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: DriverMapActivity.java From UberClone with MIT License | 6 votes |
@Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(1000); mLocationRequest.setFastestInterval(1000); 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){ }else{ checkLocationPermission(); } } }
Example 2
Source File: LocationUpdateReceiver.java From home-assistant-Android with GNU General Public License v3.0 | 6 votes |
@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 3
Source File: LocationController.java From Telegram with GNU General Public License v2.0 | 6 votes |
public LocationController(int instance) { super(instance); locationManager = (LocationManager) ApplicationLoader.applicationContext.getSystemService(Context.LOCATION_SERVICE); googleApiClient = new GoogleApiClient.Builder(ApplicationLoader.applicationContext). addApi(LocationServices.API). addConnectionCallbacks(this). addOnConnectionFailedListener(this).build(); locationRequest = new LocationRequest(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(UPDATE_INTERVAL); locationRequest.setFastestInterval(FASTEST_INTERVAL); AndroidUtilities.runOnUIThread(() -> { LocationController locationController = getAccountInstance().getLocationController(); getNotificationCenter().addObserver(locationController, NotificationCenter.didReceiveNewMessages); getNotificationCenter().addObserver(locationController, NotificationCenter.messagesDeleted); getNotificationCenter().addObserver(locationController, NotificationCenter.replaceMessagesObjects); }); loadSharingLocations(); }
Example 4
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 5
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 6
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 7
Source File: OpenLocateHelper.java From openlocate-android with MIT License | 5 votes |
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 8
Source File: GMSLocationService.java From GeometricWeather with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressLint("MissingPermission") @Override public void requestLocation(Context context, @NonNull LocationCallback callback) { if (!hasPermissions(context)) { callback.onCompleted(null); return; } locationListener = new GMSLocationListener(); locationCallback = callback; lastKnownLocation = null; client.getLastLocation().addOnSuccessListener(location -> lastKnownLocation = location); LocationRequest request = LocationRequest.create(); request.setNumUpdates(1); request.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); client.requestLocationUpdates(request, locationListener, Looper.getMainLooper()); timer.postDelayed(() -> { if (locationListener != null) { client.removeLocationUpdates(locationListener); locationListener = null; } handleLocation(lastKnownLocation); }, TIMEOUT_MILLIS); }
Example 9
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 10
Source File: CalculationModulesArrayList.java From GNSS_Compare with Apache License 2.0 | 5 votes |
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 11
Source File: SKLocation.java From SensingKit-Android with GNU Lesser General Public License v3.0 | 5 votes |
private void registerForLocationUpdates() { LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(1000); // Update location every second LocationServices.FusedLocationApi.requestLocationUpdates(mClient, locationRequest, this); }
Example 12
Source File: CustomerMapActivity.java From UberClone with MIT License | 5 votes |
@Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(1000); mLocationRequest.setFastestInterval(1000); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ if(ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){ }else{ checkLocationPermission(); } } mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper()); mMap.setMyLocationEnabled(true); }
Example 13
Source File: MainActivity.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 14
Source File: PlaceSearchFragment.java From Place-Search-Service with MIT License | 4 votes |
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 15
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 16
Source File: LocationPickerActivity.java From LocationPicker with MIT License | 4 votes |
private void getLocationRequest() { locationRequest = new LocationRequest(); locationRequest.setInterval(10000); locationRequest.setFastestInterval(3000); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); }
Example 17
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); }
Example 18
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 19
Source File: MainActivity.java From GNSS_Compare with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 20
Source File: LocationGetLocationActivity.java From coursera-android with MIT License | 4 votes |
private void continueAcquiringLocations() { // Start location services mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(POLLING_FREQ); mLocationRequest.setFastestInterval(FASTEST_UPDATE_FREQ); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder() .addLocationRequest(mLocationRequest); // Used if needed to turn on settings related to location services SettingsClient client = LocationServices.getSettingsClient(this); Task<LocationSettingsResponse> task = client.checkLocationSettings(builder.build()); task.addOnSuccessListener(this, new OnSuccessListener<LocationSettingsResponse>() { @Override public void onSuccess(LocationSettingsResponse locationSettingsResponse) { // All location settings are satisfied. The client can initialize location requests here. if (checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mLocationCallback = getLocationCallback(); mLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null); // Schedule a runnable to stop location updates after a period of time Executors.newScheduledThreadPool(1).schedule(new Runnable() { @Override public void run() { mLocationClient.removeLocationUpdates(mLocationCallback); } }, MEASURE_TIME, TimeUnit.MILLISECONDS); } } }); task.addOnFailureListener(this, new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { int statusCode = ((ApiException) e).getStatusCode(); switch (statusCode) { case CommonStatusCodes.RESOLUTION_REQUIRED: // Location settings are not satisfied, but this can be fixed // by showing the user a dialog. try { // Show the dialog by calling startResolutionForResult(), // and check the result in onActivityResult(). ResolvableApiException resolvable = (ResolvableApiException) e; resolvable.startResolutionForResult(LocationGetLocationActivity.this, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException sendEx) { // Ignore the error. } break; case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: // Location settings are not satisfied. However, we have no way // to fix the settings so we won't show the dialog. break; } } }); }