Java 类com.google.android.gms.location.FusedLocationProviderClient 实例源码

项目:LocationServices    文件:LocationFragment.java   
@DebugLog
@SuppressLint("MissingPermission")
void registerForLocationUpdates() {
    FusedLocationProviderClient locationProviderClient = getFusedLocationProviderClient();
    LocationRequest locationRequest = LocationRequest.create();
    Looper looper = Looper.myLooper();
    locationProviderClient.requestLocationUpdates(locationRequest, locationCallback, looper);
}
项目:LocationServices    文件:LocationFragment.java   
@DebugLog
@NonNull
private FusedLocationProviderClient getFusedLocationProviderClient() {
    if (fusedLocationProviderClient == null) {
        fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(getActivity());
    }
    return fusedLocationProviderClient;
}
项目:androidApp    文件:PositionProvider.java   
private PositionProvider(Context context) {
    Log.d(TAG, "Constructor");
    fusedLocationProviderClient = new FusedLocationProviderClient(context);
    locationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            Log.d(TAG, "onLocationResult");
            onLocationChanged(locationResult.getLastLocation());
        }
    };
    listeners = new SortedList<>(PositionProviderListener.class, new InnerCallback());
    buildGoogleApiClient(context);
    Location location = new Location("");

    double last_latitude = Double.longBitsToDouble(TranSappApplication.getAppSharedPreferences()
            .getLong(PositionProvider.USER_LATITUDE, 0));
    last_latitude = last_latitude != 0 ? last_latitude : Constants.santiagoLatitude;

    double last_longitude = Double.longBitsToDouble(TranSappApplication.getAppSharedPreferences()
            .getLong(PositionProvider.USER_LONGITUDE, 0));
    last_longitude = last_longitude != 0 ? last_longitude : Constants.santiagoLongitude;

    Log.d(TAG, "load latitude: " + last_latitude);
    Log.d(TAG, "load longitude: " + last_longitude);
    location.setLatitude(last_latitude);
    location.setLongitude(last_longitude);
    lasKnownLocation = location;
}
项目:RxTask    文件:RequestLocationResultObservable.java   
public RequestLocationResultObservable(FusedLocationProviderClient client, LocationRequest request) {
    this.client = client;
    this.request = request;
}
项目:RxTask    文件:RequestLocationAvailabilityObservable.java   
public RequestLocationAvailabilityObservable(FusedLocationProviderClient client, LocationRequest
        request) {
    this.client = client;
    this.request = request;
}
项目:PhoneProfilesPlus    文件:GeofencesScanner.java   
@SuppressLint("MissingPermission")
void updateTransitionsByLastKnownLocation(final boolean startEventsHandler) {
    try {
        if (Permissions.checkLocation(context) && (mGoogleApiClient != null) && mGoogleApiClient.isConnected()) {
            PPApplication.logE("GeofenceScanner.updateTransitionsByLastKnownLocation", "xxx");
            FusedLocationProviderClient fusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
            final Context appContext = context.getApplicationContext();
            //noinspection MissingPermission
            fusedLocationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
                @Override
                public void onSuccess(Location location) {
                    // Got last known location. In some rare situations this can be null.
                    PPApplication.logE("GeofenceScanner.updateTransitionsByLastKnownLocation", "onSuccess");
                    if (location != null) {
                        synchronized (PPApplication.geofenceScannerLastLocationMutex) {
                            lastLocation.set(location);
                        }
                        PPApplication.startHandlerThread();
                        final Handler handler = new Handler(PPApplication.handlerThread.getLooper());
                        handler.post(new Runnable() {
                            @Override
                            public void run() {
                                PowerManager powerManager = (PowerManager) appContext.getSystemService(POWER_SERVICE);
                                PowerManager.WakeLock wakeLock = null;
                                if (powerManager != null) {
                                    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "GeofenceScanner.updateTransitionsByLastKnownLocation");
                                    wakeLock.acquire(10 * 60 * 1000);
                                }

                                updateGeofencesInDB();
                                if (startEventsHandler) {
                                    // start job
                                    //EventsHandlerJob.startForSensor(appContext, EventsHandler.SENSOR_TYPE_LOCATION_MODE);
                                    EventsHandler eventsHandler = new EventsHandler(appContext);
                                    eventsHandler.handleEvents(EventsHandler.SENSOR_TYPE_LOCATION_MODE/*, false*/);
                                }

                                if ((wakeLock != null) && wakeLock.isHeld())
                                    wakeLock.release();
                            }
                        });
                    }
                }
            });
        }
    } catch (Exception ignored) {}
}