Java Code Examples for com.google.android.gms.location.LocationRequest#create()
The following examples show how to use
com.google.android.gms.location.LocationRequest#create() .
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: LocationService.java From redalert-android with Apache License 2.0 | 6 votes |
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 2
Source File: AppLocationFragment.java From GooglePlayServiceLocationSupport with Apache License 2.0 | 6 votes |
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mGoogleApiAvailability = GoogleApiAvailability.getInstance(); mGoogleApiClient = new GoogleApiClient.Builder(mContext).addApi(LocationServices.API). addConnectionCallbacks(this).addOnConnectionFailedListener(this).build(); mLocationService = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); mLocationRequest = LocationRequest.create(); Bundle bundle = getArguments(); if (bundle != null) enableUpdates = bundle.getBoolean(AppLocation.REQUEST_UPDATES, true); else enableUpdates = true; }
Example 3
Source File: NotificationListener.java From android-notification-log with MIT License | 5 votes |
@SuppressLint("MissingPermission") private void startFusedLocationIntentService() { if(!Const.ENABLE_LOCATION_SERVICE) { return; } if(Util.hasPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) && Util.hasPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)) { LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER); fusedLocationPendingIntent = PendingIntent.getService(this, 0, new Intent(this, FusedLocationIntentService.class), PendingIntent.FLAG_UPDATE_CURRENT); fusedLocationClient = LocationServices.getFusedLocationProviderClient(this); fusedLocationClient.requestLocationUpdates(locationRequest, fusedLocationPendingIntent); } }
Example 4
Source File: AppLocationIntentService.java From GooglePlayServiceLocationSupport with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); mGoogleApiAvailability = GoogleApiAvailability.getInstance(); mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API). addConnectionCallbacks(this).addOnConnectionFailedListener(this).build(); mLocationService = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mLocationRequest = LocationRequest.create(); enableUpdates = true; if (!servicesConnected()) { if (!mGoogleApiClient.isConnected() || !mGoogleApiClient.isConnecting()) mGoogleApiClient.connect(); } }
Example 5
Source File: AppLocationCompatActivity.java From GooglePlayServiceLocationSupport with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mGoogleApiAvailability = GoogleApiAvailability.getInstance(); mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).enableAutoManage(this, this). addConnectionCallbacks(this).addOnConnectionFailedListener(this).build(); mLocationService = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mLocationRequest = LocationRequest.create(); Intent intent = getIntent(); enableUpdates = intent.getBooleanExtra(AppLocation.REQUEST_UPDATES, true); }
Example 6
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 7
Source File: GeoFusedSucker.java From CameraV with GNU General Public License v3.0 | 5 votes |
@Override public void onConnected(Bundle arg0) { mLocationRequest = LocationRequest.create(); mLocationRequest.setInterval(Geo.LOG_RATE); mLocationRequest.setPriority(mLocationPriority); LocationServices.FusedLocationApi.requestLocationUpdates( mGoogleApiClient, mLocationRequest, this); }
Example 8
Source File: AppLocationActivity.java From GooglePlayServiceLocationSupport with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mGoogleApiAvailability = GoogleApiAvailability.getInstance(); mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).enableAutoManage(this, new Random().nextInt(Integer.MAX_VALUE), this). addConnectionCallbacks(this).addOnConnectionFailedListener(this).build(); mLocationService = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mLocationRequest = LocationRequest.create(); Intent intent = getIntent(); enableUpdates = intent.getBooleanExtra(AppLocation.REQUEST_UPDATES, true); }
Example 9
Source File: MainActivity.java From android-location-service with Apache License 2.0 | 5 votes |
@Override public void onLocationServicesConnectionSuccessful() { LocationRequest request = LocationRequest.create(); request.setInterval(5000); // Five seconds mBackgroundLocationService.requestUpdates(request); }
Example 10
Source File: MyLocationMapActivity.java From AirMapSDK-Android with Apache License 2.0 | 5 votes |
/** * This turns on Wifi/cell location tracking using Google Play services * It shows a dismissible dialog for users that don't have location already enabled */ @SuppressLint("MissingPermission") public void turnOnLocation() { LocationRequest locationRequest = LocationRequest.create(); locationRequest.setInterval(500); locationRequest.setFastestInterval(250); locationRequest.setPriority(Utils.useGPSForLocation(this) ? LocationRequest.PRIORITY_HIGH_ACCURACY : LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); LocationSettingsRequest settingsRequest = new LocationSettingsRequest.Builder() .addLocationRequest(locationRequest) .setAlwaysShow(true) .build(); Task<LocationSettingsResponse> task = LocationServices.getSettingsClient(this).checkLocationSettings(settingsRequest); task.addOnSuccessListener(this, locationSettingsResponse -> { goToLastLocation(false); }); task.addOnFailureListener(this, e -> { if (e instanceof ResolvableApiException) { if (isLocationDialogShowing) { return; } // 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(MyLocationMapActivity.this, REQUEST_TURN_ON_LOCATION); isLocationDialogShowing = true; } catch (IntentSender.SendIntentException sendEx) { // Ignore the error. } } }); }
Example 11
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 12
Source File: TimeAttendantFastFragment.java From iBeacon-Android with Apache License 2.0 | 5 votes |
private void settingLocationRequest() { googleApiClient = new GoogleApiClient.Builder(getContext()) .addApi(LocationServices.API).build(); locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(10000); locationRequest.setFastestInterval(10000 / 2); }
Example 13
Source File: LocatrFragment.java From AndroidProgramming3e with Apache License 2.0 | 5 votes |
private void findImage() { LocationRequest request = LocationRequest.create(); request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); request.setNumUpdates(1); request.setInterval(0); LocationServices.FusedLocationApi .requestLocationUpdates(mClient, request, new LocationListener() { @Override public void onLocationChanged(Location location) { Log.i(TAG, "Got a fix: " + location); new SearchTask().execute(location); } }); }
Example 14
Source File: LocatrFragment.java From AndroidProgramming3e with Apache License 2.0 | 5 votes |
private void findImage() { LocationRequest request = LocationRequest.create(); request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); request.setNumUpdates(1); request.setInterval(0); LocationServices.FusedLocationApi .requestLocationUpdates(mClient, request, new LocationListener() { @Override public void onLocationChanged(Location location) { Log.i(TAG, "Got a fix: " + location); new SearchTask().execute(location); } }); }
Example 15
Source File: SelectDeliveryAreaActivity.java From Expert-Android-Programming with MIT License | 5 votes |
private void createListener() { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); // Update location every second listenerReady = true; if (startListener) { startListener(); } }
Example 16
Source File: ShareLocationActivity.java From ShareLocationPlugin with GNU General Public License v3.0 | 5 votes |
@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 17
Source File: AndroidLocationPlayServiceManager.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
@Override public void onConnected(Bundle bundle) { locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(1000); // Update location every second setLocationManagerStatus(AVAILABLE); }
Example 18
Source File: LocationGeofenceEditorActivity.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
private void createLocationRequest() { mLocationRequest = LocationRequest.create(); // 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 19
Source File: SamLocationRequestService.java From SamLocationAndGeocoding with MIT License | 4 votes |
private void setGoogleClient(){ mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(30 * 1000); mLocationRequest.setFastestInterval(5 * 1000); LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder() .addLocationRequest(mLocationRequest); //************************** builder.setAlwaysShow(true); //this is the key ingredient //************************** Task<LocationSettingsResponse> result = LocationServices.getSettingsClient(context).checkLocationSettings( builder.build()); result.addOnFailureListener((Activity) context, new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { int statusCode = ((ApiException) e).getStatusCode(); if (statusCode == LocationSettingsStatusCodes .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 ((Activity) context, REQUEST_CODE); } catch (IntentSender.SendIntentException sendEx) { // Ignore the error } } } }); result.addOnSuccessListener((Activity) context, new OnSuccessListener<LocationSettingsResponse>() { @Override public void onSuccess(LocationSettingsResponse locationSettingsResponse) { startLocationUpdates(); } }); }
Example 20
Source File: GeofencesScanner.java From PhoneProfilesPlus with Apache License 2.0 | 4 votes |
private void createLocationRequest() { //Log.d("GeofenceScanner.createLocationRequest", "xxx"); // check power save mode String applicationEventLocationUpdateInPowerSaveMode = ApplicationPreferences.applicationEventLocationUpdateInPowerSaveMode; //boolean powerSaveMode = PPApplication.isPowerSaveMode; boolean isPowerSaveMode = DataWrapper.isPowerSaveMode(context); if (isPowerSaveMode && applicationEventLocationUpdateInPowerSaveMode.equals("2")) { mLocationRequest = null; return; } mLocationRequest = LocationRequest.create(); /* * The desired interval for location updates. Inexact. Updates may be more or less frequent. */ int interval = 25; if (isPowerSaveMode && applicationEventLocationUpdateInPowerSaveMode.equals("1")) interval = 2 * interval; final long UPDATE_INTERVAL_IN_MILLISECONDS = interval * 1000; /* * The fastest rate for active location updates. Exact. Updates will never be more frequent * than this value. */ final long FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS = UPDATE_INTERVAL_IN_MILLISECONDS / 2; // 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); // batched location (better for Android 8.0) mLocationRequest.setMaxWaitTime(UPDATE_INTERVAL_IN_MILLISECONDS * 4); if ((!ApplicationPreferences.applicationEventLocationUseGPS) || isPowerSaveMode || (!useGPS)) { //PPApplication.logE("##### GeofenceScanner.createLocationRequest","PRIORITY_BALANCED_POWER_ACCURACY"); mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); } else { //PPApplication.logE("##### GeofenceScanner.createLocationRequest","PRIORITY_HIGH_ACCURACY"); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); } }