@Override public void onConnected(@Nullable Bundle bundle) { //Make request to get the users location mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(1000); mLocationRequest.setFastestInterval(1000); mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this); } MapStateManager mapStateManager = new MapStateManager(this); mMap.setMapType(mapStateManager.getMapType()); Log.i(TAG, "onConnected: Current location and saved maptype set!"); }
public void displayLocationSettingsRequest(final Activity activity) { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity) .addApi(LocationServices.API).build(); googleApiClient.connect(); LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(mAccuracy); locationRequest.setInterval(mInterval); locationRequest.setFastestInterval(mInterval / 2); LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder() .addLocationRequest(locationRequest); builder.setAlwaysShow(false); final PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build()); result.setResultCallback(new LocationResultCallback(activity)); }
@Override public void onConnected(@Nullable Bundle bundle) { Log.d(TAG, "Google API client connected"); // String locationProvider = LocationManager.GPS_PROVIDER; mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(5000); mLocationRequest.setFastestInterval(500); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // We should have permission as we ask for it at startup. } else { LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (servicesAvailable()) { mGoogleApiClient = new GoogleApiClient.Builder(getActivity()) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(UPDATE_INTERVAL_MS); mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTEVAL_MS); } }
@NonNull @RequiresPermission( anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission" + ".ACCESS_FINE_LOCATION"} ) public Observable<LocationResult> requestLocationRequestUpdates(LocationRequest request) { return ObservableTask.create(callback -> { LocationCallback resultCallback = new LocationCallback() { @Override public void onLocationResult(LocationResult result) { super.onLocationResult(result); callback.onNext(result); } }; callback.setDisposeListener(() -> client.removeLocationUpdates(resultCallback)); return client.requestLocationUpdates(request, resultCallback, null); }); }
@Override protected void onLocationPermissionGranted() { mockModeToggleButton.setChecked(true); final LocationRequest locationRequest = LocationRequest.create() .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) .setInterval(2000); updatedLocationSubscription = locationProvider .getUpdatedLocation(locationRequest) .map(new LocationToStringFunc()) .map(new Func1<String, String>() { int count = 0; @Override public String call(String s) { return s + " " + count++; } }) .subscribe(new DisplayTextOnViewAction(updatedLocationView)); }
@Override public void onConnected(@Nullable Bundle bundle) { mRequest = LocationRequest.create(); //TODO: 変数 mRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY) .setFastestInterval(1000) .setInterval(3000); if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), 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; } LocationServices.FusedLocationApi.requestLocationUpdates(mClient, mRequest, this); }
private void startLocationScan() { RxLocation rxLocation = new RxLocation(this); LocationRequest locationRequest = LocationRequest.create() .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) .setInterval(TimeUnit.SECONDS.toMillis(5)); rxLocationObserver = rxLocation.location() .updates(locationRequest) .subscribeOn(Schedulers.io()) .flatMap(location -> rxLocation.geocoding().fromLocation(location).toObservable()) .observeOn(Schedulers.io()) .subscribeWith(new DisposableObserver<Address>() { @Override public void onNext(Address address) { boolean isLocationsEnabled = App.INSTANCE.getSharedPreferences().isLocationsEnabled(); if (isLocationsEnabled) { mOWDevice.setGpsLocation(address); } else if (rxLocationObserver != null) { rxLocationObserver.dispose(); } } @Override public void onError(Throwable e) { Log.e(TAG, "onError: error retreiving location", e); } @Override public void onComplete() { Log.d(TAG, "onComplete: "); } }); }
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); }
@Override public void onConnected(@Nullable Bundle bundle) { long interval = 100L; 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(this.mGoogleApiClient, mLocationRequest, this); }
private void getLocation() { mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .addApi(Places.GEO_DATA_API) .addApi(Places.PLACE_DETECTION_API) .enableAutoManage(this, this) .build(); mLocationRequest = LocationRequest.create() .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) .setInterval(10 * 1000) .setFastestInterval(1 * 1000); }
@SuppressWarnings("MissingPermission") private void requestLocationAndWeather() { Log.d(TAG, "requesting location"); RxLocation rxLocation = new RxLocation(getApplicationContext()); LocationRequest locationRequest = LocationRequest.create() .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) .setNumUpdates(1); rxLocation.location().updates(locationRequest) .flatMap(location -> { Log.d(TAG, "requesting weather"); String key = "abf1b0eed723ba91680f088d90290e6a"; return mDarkSkyApi.forecast(key, location.getLatitude(), location.getLongitude()) .subscribeOn(Schedulers.io()); }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(weatherDataJson -> { String currentWeather = weatherDataJson.get("currently").getAsJsonObject() .get("summary").getAsString(); mTextView.setText(currentWeather); }); }
@Override public void onConnected(Bundle bundle) { Toast.makeText(this, "onConnected", Toast.LENGTH_SHORT).show(); mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(1000); mLocationRequest.setFastestInterval(1000); mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); //mLocationRequest.setSmallestDisplacement(0.1F); 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) { // 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; } LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this); }
@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; } }
@Override public void onConnected(Bundle bundle) { //inicializa list view adapter=new ArrayAdapter<Location>(this, android.R.layout.simple_list_item_1, data); setListAdapter(adapter); //define requisicao para obter localizacao //objeto define quantos updates serao necessarios //deadline para desistir se nao conseguir obter location //intervalo //otimizacao de energia, caso aplicavel locationRequest = new LocationRequest() .setNumUpdates(5) .setExpirationDuration(60000) .setInterval(1000) .setPriority(LocationRequest.PRIORITY_LOW_POWER); LocationSettingsRequest.Builder b = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest); PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(playServices, b.build()); result.setResultCallback(this); }
private Single<Location> getLocation(LocationRequest request) { if (!shouldRequestNewLocation()) { return Single.just(mLastLocation); } return mFusedLocation.getLocation(request) .doOnSuccess(new Consumer<Location>() { @Override public void accept(Location location) throws Exception { setLocationCache(location); } }) .timeout(LOCATION_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS) .onErrorResumeNext(new Function<Throwable, SingleSource<? extends Location>>() { @Override public SingleSource<? extends Location> apply(Throwable e) throws Exception { if (e instanceof TimeoutException && mLastLocation == null) { return Single.error(new LocationTimeoutException()); } else if (mLastLocation == null) { return Single.error(e); } else { return Single.just(mLastLocation); } } }); }
@Override public void onConnected(Bundle bundle) { LocationRequest locationRequest = new LocationRequest(); locationRequest.setInterval(1500); locationRequest.setFastestInterval(1500); locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this); } getLocation(); // Display # of spawn points loaded. // Make sure we have a location first. // If we run loadSpawnPoints before Google Play Services finds the location, we get a crash. if (mLastLocation != null) { loadSpawnPoints(); } else { Toast.makeText(MapsActivity.this, "Location could not be detected, no spawn points loaded (try reloading from menu)", Toast.LENGTH_LONG).show(); } mPolygonPointsGreen = Circles.loadAllPolygons(MapsActivity.this, mMap, mMarkerTransparency); }
@Override public int onStartCommand(Intent intent, int flags, int startId) { mLocationClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); mLocationRequest.setInterval(Constants.LOCATION_INTERVAL); mLocationRequest.setFastestInterval(Constants.FASTEST_LOCATION_INTERVAL); int priority = LocationRequest.PRIORITY_HIGH_ACCURACY; mLocationRequest.setPriority(priority); mLocationClient.connect(); return START_STICKY; }
@Override public void requestLocationUpdates() { LocationRequest request = LocationRequest.create(); if (interval != null) { request.setInterval(interval); } if (fastestInterval != null) { request.setFastestInterval(fastestInterval); } if (smallestDisplacement != null) { request.setSmallestDisplacement(smallestDisplacement); } updateRequestPriority(request); if (googleApiClient.isConnected()) { //noinspection MissingPermission LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, request, this); } }
/** * Tests for requestLocation. * * @throws Exception */ @Test public void requestLocation() throws Exception { GoogleApiClient mockGoogleApiClient = mock(GoogleApiClient.class); doReturn(true).when(mockGoogleApiClient).isConnected(); LocationManager mockLocationManager = spy(mLocationManager); Whitebox.setInternalState(mockLocationManager, "googleApiClient", mockGoogleApiClient); FusedLocationProviderApi mockLocationProviderApi = mock(FusedLocationProviderApi.class); Whitebox.setInternalState(LocationServices.class, "FusedLocationApi", mockLocationProviderApi); // Testing when a customer did not disableLocationCollection. Whitebox.invokeMethod(mockLocationManager, "requestLocation"); verify(mockLocationProviderApi).requestLocationUpdates(any(GoogleApiClient.class), any(LocationRequest.class), any(LocationListener.class)); // Testing when a customer disableLocationCollection. Leanplum.disableLocationCollection(); Whitebox.invokeMethod(mockLocationManager, "requestLocation"); verifyNoMoreInteractions(mockLocationProviderApi); }
@Override public void onConnected(Bundle bundle) { LocationRequest request = new LocationRequest(); request.setInterval(mFirebaseRemoteConfig.getLong("LOCATION_REQUEST_INTERVAL")); request.setFastestInterval(mFirebaseRemoteConfig.getLong ("LOCATION_REQUEST_INTERVAL_FASTEST")); request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, request, TrackerService.this); setStatusMessage(R.string.tracking); // Hold a partial wake lock to keep CPU awake when the we're tracking location. PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakelock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); mWakelock.acquire(); }
private void configureLocationConnection() { LocationRequest locationRequest = createLocationRequest(); LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest); PendingResult<LocationSettingsResult> locationSettingsResultPendingResult = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build()); locationSettingsResultPendingResult .setResultCallback(new ResultCallback<LocationSettingsResult>() { @Override public void onResult(LocationSettingsResult result) { if (LocationSettingsStatusCodes.SUCCESS != result.getStatus().getStatusCode()) { Intent localIntent = new Intent(Constants.GOOGLE_API).putExtra(Constants.GOOGLE_API_LOCATION_RESULT, result.getStatus()); LocalBroadcastManager.getInstance(ParcoursService.this).sendBroadcast(localIntent); } } }); // noinspection MissingPermission : permissions dans le manifest LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this); }
private void setUpComponents() { _locationRequest = new LocationRequest(); _locationRequest.setInterval(10000); _locationRequest.setFastestInterval(5000); _locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); _googleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); }
@Override public void onConnected(@Nullable Bundle bundle) { mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(100); mLocationRequest.setFastestInterval(100); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this); } }
/** * 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); }
private void createLocationRequest(String precisionLevel) { Log.d(TAG, "createLocationRequest()"); locationRequest = new LocationRequest(); locationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS_PRECISION_HIGHEST); locationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS_PRECISION_HIGHEST); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); }
@RequiresPermission( anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission" + ".ACCESS_FINE_LOCATION"} ) public Completable requestLocationUpdates(LocationRequest request, PendingIntent callbackIntent) { return CompletableTask.create(() -> client.requestLocationUpdates(request, callbackIntent)); }
public void setup(final Callback successCallback, final Callback errorCallback, final int interval, final boolean requestHighAccuracy) { mInterval = interval; mErrorCallback = errorCallback; mSuccessCallback = successCallback; if (requestHighAccuracy) { mAccuracy = LocationRequest.PRIORITY_HIGH_ACCURACY; } else { mAccuracy = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY; } }
/** * Method to initialize LocationRequest */ protected void createLocationRequest() { mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(10000); mLocationRequest.setFastestInterval(5000); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY | LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); }
/** * @param logger for custom logging * @param ctx application context to prevent leaks * @param request location request to define * @param googleApiClient needed for turning on locations api */ LocationGetterImpl(Logger logger, Context ctx, LocationRequest request, GoogleApiClient googleApiClient) { this.logger = logger; this.googleApiClient = googleApiClient; appContext = ctx; locationRequest = request; }
private LocationRequest getLocationRequestByParams(long fastestInterval, long interval, int priority) { LocationRequest locationrequest = new LocationRequest(); locationrequest.setFastestInterval(fastestInterval); locationrequest.setInterval(interval); locationrequest.setPriority(priority); return locationrequest; }
private void startLocationUpdates() { Log.i(TAG, "startLocationUpdates()"); LocationRequest locationRequest = LocationRequest.create() .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) .setInterval(UPDATE_INTERVAL) .setFastestInterval(FASTEST_INTERVAL); if (checkPermission()) { LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this, Looper.getMainLooper()); } }
@Override public void onConnected(@Nullable Bundle bundle) { locationRequest = new LocationRequest(); locationRequest.setInterval(1000); locationRequest.setFastestInterval(1000); locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { LocationServices.FusedLocationApi.requestLocationUpdates(client, locationRequest, this); } }
@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); } }
private void connectToGoogleClient() { ConnectionManager _connManager = new ConnectionManager(); _client = new GoogleApiClient.Builder(_activity) .addConnectionCallbacks(_connManager) .addOnConnectionFailedListener(_connManager) .addApi(LocationServices.API) .build(); _locationRequest = new LocationRequest() .setInterval(5) .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); _client.connect(); }
private LocationRequest getLocationRequest() { LocationRequest request = new LocationRequest(); request.setPriority(accuracy.getLocationRequestAccuracy()); request.setInterval(locationRequestIntervalInSecs * 1000); request.setFastestInterval(Constants.DEFAULT_FAST_LOCATION_INTERVAL_SEC * 1000); return request; }
public Observable<Location> locationLowPower() { return location(LocationRequest.create() .setPriority(LocationRequest.PRIORITY_LOW_POWER) .setInterval(interval), Manifest.permission.ACCESS_COARSE_LOCATION ); }
private void enableGPSViaPlayServices() { Crashlytics.log(Log.INFO, MainActivity.class.getSimpleName(), "enableGPSViaPlayServices()"); googleApiClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .build(); googleApiClient.connect(); LocationSettingsRequest locationSettingsRequest = new LocationSettingsRequest.Builder() .addLocationRequest(new LocationRequest().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)) .setAlwaysShow(true) .build(); LocationServices.SettingsApi.checkLocationSettings(googleApiClient, locationSettingsRequest) .setResultCallback(new ResultCallback<LocationSettingsResult>() { @Override public void onResult(@NonNull LocationSettingsResult result) { boolean showingLocationSettingsDialog = false; if (result.getStatus().getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) { try { //Show location settings change dialog and check the result in onActivityResult() result.getStatus().startResolutionForResult(MainActivity.this, REQUEST_LOCATION); showingLocationSettingsDialog = true; Crashlytics.log(Log.INFO, MainActivity.class.getSimpleName(), "Showing PlayServices GPS settings dialog"); } catch (Exception e) { Crashlytics.log(Log.ERROR, MainActivity.class.getSimpleName(), "Error showing PlayServices GPS settings dialog"); Crashlytics.logException(e); } } if (!showingLocationSettingsDialog) { showNoGPSAlert(); //Ask user to manually enable GPS googleApiClient.disconnect(); } } }); }
@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; }
@Override public void onConnected(@Nullable Bundle bundle) { LocationRequest locationRequest = new LocationRequest(); locationRequest.setInterval(REQUEST_INTERVAL); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { // Request location updates from the Google API client LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this); } }