com.google.android.gms.location.FusedLocationProviderClient.requestLocationUpdates()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中com.google.android.gms.location.FusedLocationProviderClient.requestLocationUpdates()方法的一些代码示例,展示了FusedLocationProviderClient.requestLocationUpdates()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FusedLocationProviderClient.requestLocationUpdates()方法的具体详情如下:
包路径:com.google.android.gms.location.FusedLocationProviderClient
类名称:FusedLocationProviderClient
方法名:requestLocationUpdates

FusedLocationProviderClient.requestLocationUpdates介绍

暂无

代码示例

代码示例来源:origin: commonsguy/cw-omnibus

@SuppressLint("MissingPermission")
private void findLocation() {
 request=buildLocationRequest();
 client.requestLocationUpdates(request, cb, Looper.getMainLooper())
  .addOnFailureListener(this, e -> {
   Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
   Log.e(getClass().getSimpleName(), "Exception getting location", e);
  });
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

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);
 }
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

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);
 }
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

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);
 }
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

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);
 }
}

代码示例来源:origin: kingsammalik/SamLocationAndGeocoding

public void startLocationUpdates() {
  if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(context, 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.getFusedLocationProviderClient(context).requestLocationUpdates(
       mLocationRequest,this, null);
  Log.d("LocationRequestService", "Location update started ..............: ");
}

代码示例来源:origin: neXenio/BLE-Indoor-Positioning

@SuppressLint("MissingPermission")
public static void startRequestingLocationUpdates() {
  AndroidLocationProvider instance = getInstance();
  if (instance.isRequestingLocationUpdates) {
    return;
  }
  if (!instance.hasLocationPermission()) {
    return;
  }
  Log.d(TAG, "Starting to request location updates");
  if (instance.locationListeners.isEmpty()) {
    Log.w(TAG, "There are no location listeners registered to process location updates");
  }
  instance.fusedLocationClient.requestLocationUpdates(instance.getLocationRequest(), instance.getLocationCallback(), null);
  instance.isRequestingLocationUpdates = true;
}

代码示例来源:origin: google-developer-training/android-advanced

/**
 * Starts tracking the device. Checks for
 * permissions, and requests them if they aren't present. If they are,
 * requests periodic location updates, sets a loading text and starts the
 * animation.
 */
private void startTrackingLocation() {
  if (ActivityCompat.checkSelfPermission(this,
      Manifest.permission.ACCESS_FINE_LOCATION)
      != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this, new String[]
            {Manifest.permission.ACCESS_FINE_LOCATION},
        REQUEST_LOCATION_PERMISSION);
  } else {
    mTrackingLocation = true;
    mFusedLocationClient.requestLocationUpdates
        (getLocationRequest(),
            mLocationCallback,
            null /* Looper */);
    // Set a loading text while you wait for the address to be
    // returned
    mLocationTextView.setText(getString(R.string.address_text,
        getString(R.string.loading),
        System.currentTimeMillis()));
    mLocationButton.setText(R.string.stop_tracking_location);
    mRotateAnim.start();
  }
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

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);
 }
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

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);
 }
}

代码示例来源:origin: google-developer-training/android-advanced

/**
 * Starts tracking the device. Checks for
 * permissions, and requests them if they aren't present. If they are,
 * requests periodic location updates, sets a loading text and starts the
 * animation.
 */
private void startTrackingLocation() {
  if (ActivityCompat.checkSelfPermission(this,
      Manifest.permission.ACCESS_FINE_LOCATION)
      != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this, new String[]
            {Manifest.permission.ACCESS_FINE_LOCATION},
        REQUEST_LOCATION_PERMISSION);
  } else {
    mTrackingLocation = true;
    mFusedLocationClient.requestLocationUpdates
        (getLocationRequest(),
            mLocationCallback,
            null /* Looper */);
    // Set a loading text while you wait for the address to be
    // returned
    mLocationTextView.setText(getString(R.string.address_text,
        getString(R.string.loading), // Name
        getString(R.string.loading), // Address
        new Date())); // Timestamp
    mLocationButton.setText(R.string.stop_tracking_location);
    mRotateAnim.start();
  }
}

代码示例来源:origin: google-developer-training/android-advanced

/**
 * Starts tracking the device. Checks for
 * permissions, and requests them if they aren't present. If they are,
 * requests periodic location updates, sets a loading text and starts the
 * animation.
 */
private void startTrackingLocation() {
  if (ActivityCompat.checkSelfPermission(this,
      Manifest.permission.ACCESS_FINE_LOCATION)
      != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this, new String[]
            {Manifest.permission.ACCESS_FINE_LOCATION},
        REQUEST_LOCATION_PERMISSION);
  } else {
    mTrackingLocation = true;
    mFusedLocationClient.requestLocationUpdates
        (getLocationRequest(),
            mLocationCallback,
            null /* Looper */);
    // Set a loading text while you wait for the address to be
    // returned
    mLocationTextView.setText(getString(R.string.address_text,
        getString(R.string.loading), // Name
        getString(R.string.loading), // Address
        new Date())); // Timestamp
    mLocationButton.setText(R.string.stop_tracking_location);
    mRotateAnim.start();
  }
}

代码示例来源:origin: TeamWalrus/Walrus

fusedLocationProviderClient.requestLocationUpdates(locationRequest,
    new LocationCallback() {
      @Override

代码示例来源:origin: owntracks/android

mFusedLocationClient.requestLocationUpdates(request, locationCallback,  runner.getBackgroundHandler().getLooper());

相关文章