Search in sources :

Example 11 with Place

use of com.google.android.libraries.places.api.model.Place in project android-places-demos by googlemaps.

the class PlacePhotosActivity method getPlacePhoto.

private void getPlacePhoto() {
    // [START maps_places_get_place_photos]
    // Define a Place ID.
    final String placeId = "INSERT_PLACE_ID_HERE";
    // Specify fields. Requests for photos must always have the PHOTO_METADATAS field.
    final List<Place.Field> fields = Collections.singletonList(Place.Field.PHOTO_METADATAS);
    // Get a Place object (this example uses fetchPlace(), but you can also use findCurrentPlace())
    final FetchPlaceRequest placeRequest = FetchPlaceRequest.newInstance(placeId, fields);
    placesClient.fetchPlace(placeRequest).addOnSuccessListener((response) -> {
        final Place place = response.getPlace();
        // Get the photo metadata.
        final List<PhotoMetadata> metadata = place.getPhotoMetadatas();
        if (metadata == null || metadata.isEmpty()) {
            Log.w(TAG, "No photo metadata.");
            return;
        }
        final PhotoMetadata photoMetadata = metadata.get(0);
        // Get the attribution text.
        final String attributions = photoMetadata.getAttributions();
        // Create a FetchPhotoRequest.
        final FetchPhotoRequest photoRequest = FetchPhotoRequest.builder(photoMetadata).setMaxWidth(// Optional.
        500).setMaxHeight(// Optional.
        300).build();
        placesClient.fetchPhoto(photoRequest).addOnSuccessListener((fetchPhotoResponse) -> {
            Bitmap bitmap = fetchPhotoResponse.getBitmap();
            imageView.setImageBitmap(bitmap);
        }).addOnFailureListener((exception) -> {
            if (exception instanceof ApiException) {
                final ApiException apiException = (ApiException) exception;
                Log.e(TAG, "Place not found: " + exception.getMessage());
                final int statusCode = apiException.getStatusCode();
            // TODO: Handle error with given status code.
            }
        });
    });
// [END maps_places_get_place_photos]
}
Also used : PhotoMetadata(com.google.android.libraries.places.api.model.PhotoMetadata) List(java.util.List) Bitmap(android.graphics.Bitmap) ImageView(android.widget.ImageView) PlacesClient(com.google.android.libraries.places.api.net.PlacesClient) Place(com.google.android.libraries.places.api.model.Place) PhotoMetadata(com.google.android.libraries.places.api.model.PhotoMetadata) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) ApiException(com.google.android.gms.common.api.ApiException) FetchPlaceRequest(com.google.android.libraries.places.api.net.FetchPlaceRequest) Collections(java.util.Collections) Log(android.util.Log) FetchPhotoRequest(com.google.android.libraries.places.api.net.FetchPhotoRequest) FetchPlaceRequest(com.google.android.libraries.places.api.net.FetchPlaceRequest) Bitmap(android.graphics.Bitmap) FetchPhotoRequest(com.google.android.libraries.places.api.net.FetchPhotoRequest) Place(com.google.android.libraries.places.api.model.Place) ApiException(com.google.android.gms.common.api.ApiException)

Example 12 with Place

use of com.google.android.libraries.places.api.model.Place in project react-native-google-places by tolu360.

the class RNGooglePlacesModule method onActivityResult.

/**
 * Called after the autocomplete activity has finished to return its result.
 */
@Override
public void onActivityResult(Activity activity, final int requestCode, final int resultCode, final Intent intent) {
    // Check that the result was from the autocomplete widget.
    if (requestCode == AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == AutocompleteActivity.RESULT_OK) {
            Place place = Autocomplete.getPlaceFromIntent(intent);
            WritableMap map = propertiesMapForPlace(place, this.lastSelectedFields);
            resolvePromise(map);
        } else if (resultCode == AutocompleteActivity.RESULT_ERROR) {
            Status status = Autocomplete.getStatusFromIntent(intent);
            rejectPromise("E_RESULT_ERROR", new Error(status.getStatusMessage()));
        } else if (resultCode == AutocompleteActivity.RESULT_CANCELED) {
            rejectPromise("E_USER_CANCELED", new Error("Search cancelled"));
        }
    }
}
Also used : Status(com.google.android.gms.common.api.Status) WritableMap(com.facebook.react.bridge.WritableMap) Place(com.google.android.libraries.places.api.model.Place)

Example 13 with Place

use of com.google.android.libraries.places.api.model.Place in project react-native-google-places by tolu360.

the class RNGooglePlacesModule method lookUpPlaceByID.

@ReactMethod
public void lookUpPlaceByID(String placeID, ReadableArray fields, final Promise promise) {
    this.pendingPromise = promise;
    if (!Places.isInitialized()) {
        promise.reject("E_API_KEY_ERROR", new Error("No API key defined in gradle.properties or errors initializing Places"));
        return;
    }
    List<Place.Field> selectedFields = getPlaceFields(fields.toArrayList(), false);
    FetchPlaceRequest request = FetchPlaceRequest.builder(placeID, selectedFields).build();
    placesClient.fetchPlace(request).addOnSuccessListener((response) -> {
        Place place = response.getPlace();
        WritableMap map = propertiesMapForPlace(place, selectedFields);
        promise.resolve(map);
    }).addOnFailureListener((exception) -> {
        promise.reject("E_PLACE_DETAILS_ERROR", new Error(exception.getMessage()));
    });
}
Also used : TypeFilter(com.google.android.libraries.places.api.model.TypeFilter) AutocompleteSessionToken(com.google.android.libraries.places.api.model.AutocompleteSessionToken) Arrays(java.util.Arrays) Bundle(android.os.Bundle) FindAutocompletePredictionsResponse(com.google.android.libraries.places.api.net.FindAutocompletePredictionsResponse) PackageManager(android.content.pm.PackageManager) PlaceLikelihood(com.google.android.libraries.places.api.model.PlaceLikelihood) ACCESS_FINE_LOCATION(android.Manifest.permission.ACCESS_FINE_LOCATION) FindCurrentPlaceRequest(com.google.android.libraries.places.api.net.FindCurrentPlaceRequest) PlaceSelectionListener(com.google.android.libraries.places.widget.listener.PlaceSelectionListener) FindCurrentPlaceResponse(com.google.android.libraries.places.api.net.FindCurrentPlaceResponse) WritableNativeArray(com.facebook.react.bridge.WritableNativeArray) FetchPlaceResponse(com.google.android.libraries.places.api.net.FetchPlaceResponse) Log(android.util.Log) LocationBias(com.google.android.libraries.places.api.model.LocationBias) ReadableMap(com.facebook.react.bridge.ReadableMap) LatLng(com.google.android.gms.maps.model.LatLng) FindAutocompletePredictionsRequest(com.google.android.libraries.places.api.net.FindAutocompletePredictionsRequest) ContextCompat(android.support.v4.content.ContextCompat) AutocompleteSupportFragment(com.google.android.libraries.places.widget.AutocompleteSupportFragment) Place(com.google.android.libraries.places.api.model.Place) ActivityCompat(android.support.v4.app.ActivityCompat) RequiresPermission(android.support.annotation.RequiresPermission) Objects(java.util.Objects) List(java.util.List) ReactMethod(com.facebook.react.bridge.ReactMethod) Arguments(com.facebook.react.bridge.Arguments) Nullable(android.support.annotation.Nullable) AutocompleteActivityMode(com.google.android.libraries.places.widget.model.AutocompleteActivityMode) LocationRestriction(com.google.android.libraries.places.api.model.LocationRestriction) AutocompleteActivity(com.google.android.libraries.places.widget.AutocompleteActivity) WritableArray(com.facebook.react.bridge.WritableArray) ACCESS_WIFI_STATE(android.Manifest.permission.ACCESS_WIFI_STATE) PlacesClient(com.google.android.libraries.places.api.net.PlacesClient) ReadableArray(com.facebook.react.bridge.ReadableArray) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) Intent(android.content.Intent) ActivityEventListener(com.facebook.react.bridge.ActivityEventListener) FetchPlaceRequest(com.google.android.libraries.places.api.net.FetchPlaceRequest) Task(com.google.android.gms.tasks.Task) ArrayList(java.util.ArrayList) Promise(com.facebook.react.bridge.Promise) IntentSender(android.content.IntentSender) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) ReactProp(com.facebook.react.uimanager.annotations.ReactProp) ReactContextBaseJavaModule(com.facebook.react.bridge.ReactContextBaseJavaModule) Places(com.google.android.libraries.places.api.Places) TextUtils(android.text.TextUtils) RectangularBounds(com.google.android.libraries.places.api.model.RectangularBounds) TimeUnit(java.util.concurrent.TimeUnit) AddressComponent(com.google.android.libraries.places.api.model.AddressComponent) Autocomplete(com.google.android.libraries.places.widget.Autocomplete) AutocompletePrediction(com.google.android.libraries.places.api.model.AutocompletePrediction) Manifest.permission(android.Manifest.permission) WritableMap(com.facebook.react.bridge.WritableMap) Status(com.google.android.gms.common.api.Status) Activity(android.app.Activity) FetchPlaceRequest(com.google.android.libraries.places.api.net.FetchPlaceRequest) WritableMap(com.facebook.react.bridge.WritableMap) Place(com.google.android.libraries.places.api.model.Place) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

Place (com.google.android.libraries.places.api.model.Place)13 Status (com.google.android.gms.common.api.Status)8 Bundle (android.os.Bundle)6 Log (android.util.Log)6 LatLng (com.google.android.gms.maps.model.LatLng)6 PlacesClient (com.google.android.libraries.places.api.net.PlacesClient)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Intent (android.content.Intent)5 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)5 FetchPlaceRequest (com.google.android.libraries.places.api.net.FetchPlaceRequest)5 AutocompleteSupportFragment (com.google.android.libraries.places.widget.AutocompleteSupportFragment)5 PlaceSelectionListener (com.google.android.libraries.places.widget.listener.PlaceSelectionListener)5 Arrays (java.util.Arrays)5 Places (com.google.android.libraries.places.api.Places)4 AutocompletePrediction (com.google.android.libraries.places.api.model.AutocompletePrediction)4 AutocompleteSessionToken (com.google.android.libraries.places.api.model.AutocompleteSessionToken)4 RectangularBounds (com.google.android.libraries.places.api.model.RectangularBounds)4 TypeFilter (com.google.android.libraries.places.api.model.TypeFilter)4 FindAutocompletePredictionsRequest (com.google.android.libraries.places.api.net.FindAutocompletePredictionsRequest)4