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

项目:RxTask    文件:RxFusedLocationProviderClient.java   
@NonNull
@RequiresPermission(
        anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission" +
                ".ACCESS_FINE_LOCATION"}
)
public Observable<LocationResult> requestLocationRequestUpdates(LocationRequest request) {
    return ObservableTask.create(callback -> {
        LocationCallback resultCallback = new LocationCallback() {
            @Override
            public void onLocationResult(LocationResult result) {
                super.onLocationResult(result);
                callback.onNext(result);
            }
        };
        callback.setDisposeListener(() -> client.removeLocationUpdates(resultCallback));
        return client.requestLocationUpdates(request, resultCallback, null);
    });
}
项目:RxTask    文件:RxFusedLocationProviderClient.java   
@NonNull
@RequiresPermission(
        anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission" +
                ".ACCESS_FINE_LOCATION"}
)
public Observable<LocationAvailability> requestLocationAvailabilityUpdates(LocationRequest
                                                                                   request) {
    return ObservableTask.create(callback -> {
        LocationCallback resultCallback = new LocationCallback() {
            @Override
            public void onLocationAvailability(LocationAvailability locationAvailability) {
                super.onLocationAvailability(locationAvailability);
                callback.onNext(locationAvailability);
            }
        };
        callback.setDisposeListener(() -> client.removeLocationUpdates(resultCallback));
        return client.requestLocationUpdates(request, resultCallback, null);

    });
}
项目:poznaj-app-android    文件:LocationService.java   
@Override
public void onCreate() {
    fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);

    locationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            super.onLocationResult(locationResult);
            onNewLocation(locationResult.getLastLocation());
        }
    };

    createLocationRequest();
    getLastLocation();

    HandlerThread handlerThread = new HandlerThread(TAG);
    handlerThread.start();
    serviceHandler = new Handler(handlerThread.getLooper());
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
项目:NightSkyGuide    文件:MainActivity.java   
private void createLocationCallback() {
    mLocationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
        super.onLocationResult(locationResult);
        mCurrentLocation = locationResult.getLastLocation();
        setLatLong(mCurrentLocation);
        //Toast.makeText(MainActivity.this, "GPS Update", Toast.LENGTH_SHORT).show();
        }
    };
}
项目:NightSkyGuide    文件:SettingsActivity.java   
public void createLocationCallback() {
    mLocationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            super.onLocationResult(locationResult);
            mCurrentLocation = locationResult.getLastLocation();
            setLatLong(mCurrentLocation);
        }
    };
}
项目:SpaceRace    文件:MapActivity.java   
/**
 * Creates a callback for receiving location events.
 */
private void createLocationCallback() {
    mLocationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(final LocationResult locationResult) {
            super.onLocationResult(locationResult);

            if (mRequestingLocationUpdates) {

                Log.i(TAG, "update event");
                Location oldLocation = mCurrentLocation;

                mCurrentLocation = locationResult.getLastLocation();

                if (initialPosition == null) {
                    initialPosition = mCurrentLocation;

                    map.moveCamera(CameraUpdateFactory.newLatLngZoom(
                            new LatLng(initialPosition.getLatitude(),
                                    initialPosition.getLongitude()), DEFAULT_ZOOM));

                    Log.d("INITIAL_POSITION", initialPosition.getLatitude() + " " +
                            initialPosition.getLongitude());

                    createAndDrawPath();
                }

                mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
                updateUI(oldLocation);
            }

        }
    };
}
项目:BLE-Indoor-Positioning    文件:AndroidLocationProvider.java   
private LocationCallback createLocationCallback() {
    return new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            Log.v(TAG, "Received location result with " + locationResult.getLocations().size() + " locations");
            onLocationUpdateReceived(locationResult.getLastLocation());
        }
    };
}
项目:WeatherPlus    文件:MainActivity.java   
private void createLocationCallBack() {
    mLocationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            super.onLocationResult(locationResult);

            mResultCallBack.onSuccess(locationResult.getLastLocation());
            stopLocationUpdates();
        }
    };
}
项目:Camera-warner    文件:LocationService.java   
@Override
public void onCreate() {
    super.onCreate();

    Log.d("LocationService", "onCreate");

    manager = new DataProviderManager();
    manager.addObserver(this);

    mClient = LocationServices.getFusedLocationProviderClient(this);

    //implementation of the location update callback
    //what happens when the service receives the user location is defined here
    callback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            lastLocation = locationResult.getLastLocation();
            Log.d("LocationService", "new location received");
            notifyUIOfNewPosition();
            //update the location providers with the new location
            manager.onLocationChanged(lastLocation);

            if (PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean(getString(R.string.pref_active_key), getResources().getBoolean(R.bool.pref_active_default))
                    && manager.isCameraNearerThan(Float.parseFloat(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString(getString(R.string.pref_radius_key), getString(R.string.pref_radius_default))), lastLocation)) {
                enableCameraWarning();
            } else {
                disableCameraWarning();
            }

        }
    };

    //build the notification for @see {@link #startForeground()} to keep the service from being killed
    startForeground(CAMERA_FOREGROUND_SERVICE_NOTIFICATION_ID, buildForegroundNotification());
}
项目:TrekAdvisor    文件:LocationService.java   
@Override
public void onCreate() {
    EventBus.getDefault().register(this);

    // Start up the thread running the service.  Note that we create a
    // separate thread because the service normally runs in the process's
    // main thread, which we don't want to block.  We also make it
    // background priority so CPU-intensive work will not disrupt our UI.
    HandlerThread thread = new HandlerThread("LocationServiceThread",
            Thread.MIN_PRIORITY);
    thread.start();

    // Get the HandlerThread's Looper and use it for our Handler
    mServiceLooper = thread.getLooper();
    mServiceHandler = new Handler(mServiceLooper);

    mServiceHandler.handleMessage(new Message());

    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this.getApplicationContext());
    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(1000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    /* Create the Gpx instance */
    mTrackPoints = new ArrayList<>();

    mLocationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            for (Location location : locationResult.getLocations()) {
                mServiceHandler.post(() -> {
                    TrackPoint.Builder pointBuilder = new TrackPoint.Builder();
                    pointBuilder.setLatitude(location.getLatitude());
                    pointBuilder.setLongitude(location.getLongitude());
                    pointBuilder.setElevation(location.getAltitude());

                    TrackPoint trackPoint = pointBuilder.build();
                    mTrackPoints.add(trackPoint);
                });
            }
        }
    };

    startLocationUpdates();
}
项目:TrekAdvisor    文件:MapViewFragment.java   
@Override
public void onAttach(Context context) {
    super.onAttach(context);
    if (context instanceof RequestManageTracksListener
            && context instanceof RequestManageMarkerListener
            && context instanceof MapProvider) {
        mRequestManageTracksListener = (RequestManageTracksListener) context;
        mRequestManageMarkerListener = (RequestManageMarkerListener) context;
        mMapProvider = (MapProvider) context;
    } else {
        throw new RuntimeException(context.toString()
                + " must implement RequestManageTracksListener, MapProvider and LocationProvider");
    }

    /* The Google api client is re-created here as the onAttach method will always be called for
     * a retained fragment.
     */
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this.getActivity().getApplicationContext());
    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(1000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    mLocationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            for (Location location : locationResult.getLocations()) {
                onLocationReceived(location);
            }
        }
    };
}
项目:googleplayAPI    文件:MainActivity.java   
/**
 * Creates a callback for receiving location events.
 */
private void createLocationCallback() {
    mLocationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            super.onLocationResult(locationResult);

            mLastLocation = locationResult.getLastLocation();
            logger.append("\n\n" + DateFormat.getTimeInstance().format(new Date()) + ": ");
            logger.append(" Lat: " + String.valueOf(mLastLocation.getLatitude()));
            logger.append(" Long: " + String.valueOf(mLastLocation.getLongitude()) + "\n");
            startIntentService();
        }
    };
}
项目:googleplayAPI    文件:MainActivity.java   
/**
 * Creates a callback for receiving location events.
 */
private void createLocationCallback() {
    mLocationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            super.onLocationResult(locationResult);

            addData(locationResult.getLastLocation());
        }
    };
}
项目:drivedata    文件:CaptureActivity.java   
@Override
public void onConnected(Bundle connectionHint) {
    Log.i("CaptureActivity", "onConnected called");
    clientReady = true;

    //Use a new thread to request location updates for the worker thread.
    //This new thread waits until the result of the request for updates is complete.
    Runnable r = new Runnable(){
        @Override
        public void run() {
            LocationRequest request = new LocationRequest();
            request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(5000);

            LocationCallback locationCallback = new LocationCallback() {
                @Override
                public void onLocationAvailability(LocationAvailability availability) {
                    if (!availability.isLocationAvailable()) {
                        locationReady = false;
                    }
                }

                public void onLocationResult(LocationResult result) {
                    newestLocation = result.getLastLocation();
                }
            };

            PendingResult<Status> requestResult = LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, request, locationCallback, handler.getLooper());
            Status requestStatus = requestResult.await();
            locationReady = true;
            if(requestStatus.isSuccess()) {
                locationReady = true;
                Log.i("CaptureActivity", "Location update request result success!");
            }else {
                Log.i("CaptureActivity", "Location update request result: failure!");
            }
        }
    };
    new Thread(r).start();
}
项目:drivedata    文件:CaptureActivity.java   
@Override
public void onConnected(Bundle connectionHint) {
    Log.i("CaptureActivity", "onConnected called");
    clientReady = true;

    //Use a new thread to request location updates for the worker thread.
    //This new thread waits until the result of the request for updates is complete.
    Runnable r = new Runnable(){
        @Override
        public void run() {
            LocationRequest request = new LocationRequest();
            request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(5000);

            LocationCallback locationCallback = new LocationCallback() {
                @Override
                public void onLocationAvailability(LocationAvailability availability) {
                    if (!availability.isLocationAvailable()) {
                        locationReady = false;
                    }
                }

                public void onLocationResult(LocationResult result) {
                    newestLocation = result.getLastLocation();
                }
            };

            PendingResult<Status> requestResult = LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, request, locationCallback, handler.getLooper());
            Status requestStatus = requestResult.await();
            locationReady = true;
            if(requestStatus.isSuccess()) {
                locationReady = true;
                Log.i("CaptureActivity", "Location update request result success!");
            }else {
                Log.i("CaptureActivity", "Location update request result: failure!");
            }
        }
    };
    new Thread(r).start();
}
项目: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;
}
项目:android-play-location    文件:MainActivity.java   
/**
 * Creates a callback for receiving location events.
 */
private void createLocationCallback() {
    mLocationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            super.onLocationResult(locationResult);

            mCurrentLocation = locationResult.getLastLocation();
            mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
            updateLocationUI();
        }
    };
}
项目:android-play-location    文件:LocationUpdatesService.java   
@Override
public void onCreate() {
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);

    mLocationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            super.onLocationResult(locationResult);
            onNewLocation(locationResult.getLastLocation());
        }
    };

    createLocationRequest();
    getLastLocation();

    HandlerThread handlerThread = new HandlerThread(TAG);
    handlerThread.start();
    mServiceHandler = new Handler(handlerThread.getLooper());
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    // Android O requires a Notification Channel.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence name = getString(R.string.app_name);
        // Create the channel for the notification
        NotificationChannel mChannel =
                new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_DEFAULT);

        // Set the Notification Channel for the Notification Manager.
        mNotificationManager.createNotificationChannel(mChannel);
    }
}
项目:WalkMyAndroid-Location    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mLocationButton = (Button) findViewById(R.id.button_location);
    mLocationTextView = (TextView) findViewById(R.id.textview_location);
    mAndroidImageView = (ImageView) findViewById(R.id.imageview_android);


    // Initialize the FusedLocationClient.
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(
            this);

    // Set up the animation.
    mRotateAnim = (AnimatorSet) AnimatorInflater.loadAnimator
            (this, R.animator.rotate);
    mRotateAnim.setTarget(mAndroidImageView);

    // Restore the state if the activity is recreated.
    if (savedInstanceState != null) {
        mTrackingLocation = savedInstanceState.getBoolean(
                TRACKING_LOCATION_KEY);
    }

    // Set the listener for the location button.
    mLocationButton.setOnClickListener(new View.OnClickListener() {
        /**
         * Toggle the tracking state.
         * @param v The track location button.
         */
        @Override
        public void onClick(View v) {
            if (!mTrackingLocation) {
                startTrackingLocation();
                mTrackingLocation = true;
            } else {
                stopTrackingLocation();
                mTrackingLocation = false;
            }
        }
    });

    // Initialize the location callbacks.
    mLocationCallback = new LocationCallback() {
        /**
         * This is the callback that is triggered when the
         * FusedLocationClient updates your location.
         * @param locationResult The result containing the device location.
         */
        @Override
        public void onLocationResult(LocationResult locationResult) {
            // If tracking is turned on, reverse geocode into an address
            if (mTrackingLocation) {
                new FetchAddressTask().execute(locationResult
                        .getLastLocation());
            }
        }
    };
}
项目:LocationAware    文件:LocationProvider.java   
@SuppressLint("MissingPermission")
public void startLocationUpdates(LocationCallback locationCallback) {
  locationProviderClient.requestLocationUpdates(getLocationRequest(), locationCallback, null);
}
项目:LocationAware    文件:LocationProvider.java   
public void stopLocationUpdates(LocationCallback locationCallback) {
  locationProviderClient.removeLocationUpdates(locationCallback);
}
项目:BLE-Indoor-Positioning    文件:AndroidLocationProvider.java   
private LocationCallback getLocationCallback() {
    if (locationCallback == null) {
        locationCallback = createLocationCallback();
    }
    return locationCallback;
}
项目:RxLocation    文件:MockFusedLocationProvider.java   
@Override
public PendingResult<Status> requestLocationUpdates(GoogleApiClient googleApiClient, LocationRequest locationRequest, LocationCallback locationCallback, Looper looper) {
    throw new UnsupportedOperationException("Stub!");
}
项目:RxLocation    文件:MockFusedLocationProvider.java   
@Override
public PendingResult<Status> removeLocationUpdates(GoogleApiClient googleApiClient, LocationCallback locationCallback) {
    throw new UnsupportedOperationException("Stub!");
}