com.google.android.gms.location.FusedLocationProviderApi类的使用及代码示例

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

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

FusedLocationProviderApi介绍

暂无

代码示例

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

  1. @SuppressWarnings("MissingPermission")
  2. void requestLocations() {
  3. PendingResult<Status> result=
  4. LocationServices.FusedLocationApi
  5. .requestLocationUpdates(getPlayServices(), request, this);
  6. result.setResultCallback(new ResultCallback<Status>() {
  7. @Override
  8. public void onResult(Status status) {
  9. if (status.isSuccess()) {
  10. Toast
  11. .makeText(getActivity(),
  12. R.string.location_req_success_msg,
  13. Toast.LENGTH_LONG)
  14. .show();
  15. } else {
  16. Toast
  17. .makeText(getActivity(), status.getStatusMessage(),
  18. Toast.LENGTH_LONG)
  19. .show();
  20. getActivity().finish();
  21. }
  22. }
  23. });
  24. }

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

  1. @Override
  2. public void onPause() {
  3. LocationServices.FusedLocationApi.removeLocationUpdates(
  4. getPlayServices(), this);
  5. super.onPause();
  6. }

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

  1. @SuppressWarnings("MissingPermission")
  2. @Override
  3. public void run() {
  4. Location location=
  5. LocationServices.FusedLocationApi.getLastLocation(getPlayServices());
  6. if (location==null) {
  7. getListView().postDelayed(this, 1000);
  8. }
  9. else {
  10. fetchForecast(location);
  11. }
  12. }

代码示例来源:origin: Sishin/MapLocation

  1. Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
  2. mGoogleApiClient);
  3. if (mLastLocation != null) {
  4. LocationServices.FusedLocationApi.removeLocationUpdates(
  5. mGoogleApiClient, this);
  6. mLocationRequest.setFastestInterval(5000);
  7. mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
  8. LocationServices.FusedLocationApi.requestLocationUpdates(
  9. mGoogleApiClient, mLocationRequest, this);

代码示例来源:origin: lycha/augmented-reality-example

  1. @Override
  2. public void onConnected(Bundle bundle) {
  3. LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
  4. mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
  5. mGoogleApiClient);
  6. if (mLastLocation != null) {
  7. onLocationChangedListener.onLocationChanged(mLastLocation);
  8. }
  9. }

代码示例来源:origin: adafruit/Bluefruit_LE_Connect_Android

  1. LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this);
  2. } catch (SecurityException e) {
  3. Log.e(TAG, "Security exception requesting location updates: " + e);
  4. LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);

代码示例来源:origin: yayaa/LocationManager

  1. @SuppressWarnings("ResourceType")
  2. boolean getLocationAvailability() {
  3. LocationAvailability locationAvailability =
  4. LocationServices.FusedLocationApi.getLocationAvailability(googleApiClient);
  5. return locationAvailability != null && locationAvailability.isLocationAvailable();
  6. }

代码示例来源:origin: NightscoutFoundation/xDrip

  1. @SuppressLint("MissingPermission") final Location location = LocationServices.FusedLocationApi.getLastLocation(mApiClient);
  2. if (location != null) {
  3. lastLocation = location;
  4. LocationServices.FusedLocationApi.requestLocationUpdates(mApiClient,
  5. getLocationRequest(), callback, Looper.getMainLooper());
  6. });
  7. Inevitable.task("remove gps updates " + JoH.tsl(), GPS_ACTIVE_TIME,
  8. () -> LocationServices.FusedLocationApi.removeLocationUpdates(mApiClient, callback));

代码示例来源:origin: WomenWhoCode/WomenWhoCode

  1. @Override
  2. public void onConnected(Bundle bundle) {
  3. Log.i(TAG, "Location services connected.");
  4. Location mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
  5. if (mCurrentLocation == null) {
  6. LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
  7. } else {
  8. mLocationCallback.handleNewLocation(mCurrentLocation);
  9. }
  10. }

代码示例来源:origin: klaasnotfound/LocationAssistant

  1. private boolean checkLocationAvailability() {
  2. if (!googleApiClient.isConnected() || !permissionGranted) return false;
  3. try {
  4. LocationAvailability la = LocationServices.FusedLocationApi.getLocationAvailability(googleApiClient);
  5. return (la != null && la.isLocationAvailable());
  6. } catch (SecurityException e) {
  7. if (!quiet)
  8. Log.e(getClass().getSimpleName(), "Error while checking location availability:\n " + e.toString());
  9. if (listener != null)
  10. listener.onError(ErrorType.RETRIEVAL, "Could not check location availability:\n" +
  11. e.getMessage());
  12. return false;
  13. }
  14. }

代码示例来源:origin: palaima/DebugDrawer

  1. void startLocationUpdates() {
  2. googleApiClient.connect();
  3. if (connected && locationRequest != null) {
  4. isStarted = true;
  5. LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, locationListener);
  6. }
  7. }

代码示例来源:origin: jamorham/xDrip-plus

  1. @SuppressLint("MissingPermission") final Location location = LocationServices.FusedLocationApi.getLastLocation(mApiClient);
  2. if (location != null) {
  3. lastLocation = location;
  4. LocationServices.FusedLocationApi.requestLocationUpdates(mApiClient,
  5. getLocationRequest(), callback, Looper.getMainLooper());
  6. });
  7. Inevitable.task("remove gps updates " + JoH.tsl(), GPS_ACTIVE_TIME,
  8. () -> LocationServices.FusedLocationApi.removeLocationUpdates(mApiClient, callback));

代码示例来源:origin: ankitdubey021/GPSTracker

  1. @Override
  2. public void onConnected(@Nullable Bundle bundle) {
  3. Log.i("My Tracker", "Location services connected!.");
  4. if (ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  5. return;
  6. }
  7. Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
  8. fetchLocation(location);
  9. if (location == null) {
  10. if (ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  11. return;
  12. }
  13. LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
  14. }
  15. }

代码示例来源:origin: palaima/DebugDrawer

  1. void stopLocationUpdates() {
  2. if (connected && locationRequest != null) {
  3. LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, locationListener);
  4. googleApiClient.disconnect();
  5. connected = false;
  6. isStarted = false;
  7. }
  8. }
  9. }

代码示例来源:origin: palaima/DebugDrawer

  1. /**
  2. * Get last known location
  3. *
  4. * @return Location
  5. */
  6. Location getLastLocation() {
  7. return LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
  8. }

代码示例来源:origin: florent37/RxGps

  1. @Override
  2. protected void onGoogleApiClientReady(GoogleApiClient apiClient, SingleEmitter<Boolean> emitter) {
  3. //noinspection MissingPermission
  4. LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(apiClient);
  5. if (locationAvailability != null) {
  6. emitter.onSuccess(locationAvailability.isLocationAvailable());
  7. } else {
  8. emitter.onSuccess(false);
  9. }
  10. }
  11. }

代码示例来源:origin: yayaa/LocationManager

  1. @SuppressWarnings("ResourceType")
  2. void requestLocationUpdate() {
  3. LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
  4. }

代码示例来源:origin: AppLozic/Applozic-Android-SDK

  1. @Override
  2. public void onConnected(Bundle bundle) {
  3. try {
  4. Location mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
  5. if (mCurrentLocation == null) {
  6. Toast.makeText(this, R.string.waiting_for_current_location, Toast.LENGTH_SHORT).show();
  7. locationRequest = new LocationRequest();
  8. locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
  9. locationRequest.setInterval(UPDATE_INTERVAL);
  10. locationRequest.setFastestInterval(FASTEST_INTERVAL);
  11. LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
  12. }
  13. if (mCurrentLocation != null && conversation != null) {
  14. conversation.attachLocation(mCurrentLocation);
  15. }
  16. } catch (Exception e) {
  17. }
  18. }

代码示例来源:origin: AppLozic/Applozic-Android-SDK

  1. @Override
  2. public void onLocationChanged(Location location) {
  3. try {
  4. LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, this);
  5. if (location != null) {
  6. mCurrentLocation = location;
  7. }
  8. } catch (Exception e) {
  9. }
  10. }

代码示例来源:origin: yayaa/LocationManager

  1. @SuppressWarnings("ResourceType")
  2. Location getLastLocation() {
  3. return LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
  4. }

相关文章