Search in sources :

Example 1 with CurrentPlaceRequestParams

use of com.facebook.places.model.CurrentPlaceRequestParams in project facebook-android-sdk by facebook.

the class PlaceManager method newCurrentPlaceRequest.

/**
 * Creates a new current place request.
 * <p>
 * The current place request estimates the place where the user is currently located.
 * The response contains a list of places and their associated confidence levels.
 * <p>
 * If a location is not specified in {@link CurrentPlaceRequestParams}, then the SDK
 * retrieves the current location using {@link android.location.LocationManager}.
 *
 * @param requestParams the request parameters. See {@link CurrentPlaceRequestParams}
 * @param callback a {@link OnRequestReadyCallback} that is invoked when the
 * {@link GraphRequest} has been created and is ready to be executed.
 */
public static void newCurrentPlaceRequest(final CurrentPlaceRequestParams requestParams, final OnRequestReadyCallback callback) {
    Location location = requestParams.getLocation();
    CurrentPlaceRequestParams.ScanMode scanMode = requestParams.getScanMode();
    LocationPackageRequestParams.Builder builder = new LocationPackageRequestParams.Builder();
    // Don't scan for a location if one is provided.
    builder.setLocationScanEnabled(location == null);
    if (scanMode != null && scanMode == CurrentPlaceRequestParams.ScanMode.LOW_LATENCY) {
        // In low-latency mode, avoid active Wi-Fi scanning which can takes
        // several seconds.
        builder.setWifiActiveScanAllowed(false);
    }
    LocationPackageManager.requestLocationPackage(builder.build(), new LocationPackageManager.Listener() {

        @Override
        public void onLocationPackage(LocationPackage locationPackage) {
            if (locationPackage.locationError != null) {
                callback.onLocationError(getLocationError(locationPackage.locationError));
            } else {
                Bundle parameters = getCurrentPlaceParameters(requestParams, locationPackage);
                GraphRequest graphRequest = new GraphRequest(AccessToken.getCurrentAccessToken(), CURRENT_PLACE_RESULTS, parameters, HttpMethod.GET);
                callback.onRequestReady(graphRequest);
            }
        }
    });
}
Also used : LocationPackageRequestParams(com.facebook.places.internal.LocationPackageRequestParams) GraphRequest(com.facebook.GraphRequest) LocationPackage(com.facebook.places.internal.LocationPackage) Bundle(android.os.Bundle) CurrentPlaceRequestParams(com.facebook.places.model.CurrentPlaceRequestParams) LocationPackageManager(com.facebook.places.internal.LocationPackageManager) Location(android.location.Location)

Aggregations

Location (android.location.Location)1 Bundle (android.os.Bundle)1 GraphRequest (com.facebook.GraphRequest)1 LocationPackage (com.facebook.places.internal.LocationPackage)1 LocationPackageManager (com.facebook.places.internal.LocationPackageManager)1 LocationPackageRequestParams (com.facebook.places.internal.LocationPackageRequestParams)1 CurrentPlaceRequestParams (com.facebook.places.model.CurrentPlaceRequestParams)1