Java Code Examples for com.google.android.gms.location.FusedLocationProviderClient#requestLocationUpdates()

The following examples show how to use com.google.android.gms.location.FusedLocationProviderClient#requestLocationUpdates() . 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: CalculationModulesArrayList.java    From GNSS_Compare with Apache License 2.0 6 votes vote down vote up
public void registerForGnssUpdates(FusedLocationProviderClient fusedLocationClient, LocationManager locationManager){
    try {

        fusedLocationProviderClientReference = fusedLocationClient;
        locationManagerReference = locationManager;

        fusedLocationClient.requestLocationUpdates(
                locationRequest,
                locationCallback,
                Looper.myLooper());

        locationManager.registerGnssMeasurementsCallback(
                gnssCallback);

    } catch (SecurityException e){
        e.printStackTrace();
    }
}
 
Example 2
Source File: LocationActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
private void startTrackingLocation() {
  if (
    ActivityCompat
      .checkSelfPermission(this, ACCESS_FINE_LOCATION) == PERMISSION_GRANTED ||
      ActivityCompat
        .checkSelfPermission(this, ACCESS_COARSE_LOCATION) == PERMISSION_GRANTED) {

    FusedLocationProviderClient locationClient = LocationServices.getFusedLocationProviderClient(this);
    LocationRequest request =
      new LocationRequest()
        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
        .setInterval(5000); // Update every 5 seconds.

    locationClient.requestLocationUpdates(request, mLocationCallback, null);
  }
}
 
Example 3
Source File: LocationActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
private void listing15_8() {
  if (
    ActivityCompat
      .checkSelfPermission(this, ACCESS_FINE_LOCATION) == PERMISSION_GRANTED ||
      ActivityCompat
        .checkSelfPermission(this, ACCESS_COARSE_LOCATION) == PERMISSION_GRANTED) {

    // Listing 15-8: Requesting location updates using a Pending Intent
    FusedLocationProviderClient fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);

    LocationRequest request = new LocationRequest()
                                .setInterval(60000 * 10) // Update every 10 minutes.
                                .setPriority(LocationRequest.PRIORITY_NO_POWER);

    final int locationUpdateRC = 0;
    int flags = PendingIntent.FLAG_UPDATE_CURRENT;

    Intent intent = new Intent(this, MyLocationUpdateReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, locationUpdateRC, intent, flags);

    fusedLocationClient.requestLocationUpdates(request, pendingIntent);
  }
}
 
Example 4
Source File: LocationUpdatesBroadcastReceiver.java    From background_location_updates with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: WhereAmIActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
private void requestLocationUpdates() {
  if (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION)
        == PERMISSION_GRANTED ||
        ActivityCompat.checkSelfPermission(this, ACCESS_COARSE_LOCATION)
        == PERMISSION_GRANTED) {

    FusedLocationProviderClient fusedLocationClient
      = LocationServices.getFusedLocationProviderClient(this);

    fusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null);
  }
}
 
Example 6
Source File: WhereAmIActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
private void requestLocationUpdates() {
  if (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION)
        == PERMISSION_GRANTED ||
        ActivityCompat.checkSelfPermission(this, ACCESS_COARSE_LOCATION)
        == PERMISSION_GRANTED) {

    FusedLocationProviderClient fusedLocationClient
      = LocationServices.getFusedLocationProviderClient(this);

    fusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null);
  }
}
 
Example 7
Source File: WhereAmIActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
private void requestLocationUpdates() {
  if (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION)
        == PERMISSION_GRANTED ||
        ActivityCompat.checkSelfPermission(this, ACCESS_COARSE_LOCATION)
        == PERMISSION_GRANTED) {

    FusedLocationProviderClient fusedLocationClient
      = LocationServices.getFusedLocationProviderClient(this);

    fusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null);
  }
}
 
Example 8
Source File: WhereAmIActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
private void requestLocationUpdates() {
  if (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION)
        == PERMISSION_GRANTED ||
        ActivityCompat.checkSelfPermission(this, ACCESS_COARSE_LOCATION)
        == PERMISSION_GRANTED) {

    FusedLocationProviderClient fusedLocationClient
      = LocationServices.getFusedLocationProviderClient(this);

    fusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null);
  }
}