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]
}
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"));
}
}
}
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()));
});
}
Aggregations