use of com.google.android.libraries.places.api.Places in project android-places-demos by googlemaps.
the class ProgrammaticAutocompleteToolbarActivity method getPlacePredictions.
/**
* This method demonstrates the programmatic approach to getting place predictions. The
* parameters in this request are currently biased to Kolkata, India.
*
* @param query the plus code query string (e.g. "GCG2+3M K")
*/
private void getPlacePredictions(String query) {
// The value of 'bias' biases prediction results to the rectangular region provided
// (currently Kolkata). Modify these values to get results for another area. Make sure to
// pass in the appropriate value/s for .setCountries() in the
// FindAutocompletePredictionsRequest.Builder object as well.
final LocationBias bias = RectangularBounds.newInstance(// SW lat, lng
new LatLng(22.458744, 88.208162), // NE lat, lng
new LatLng(22.730671, 88.524896));
// Create a new programmatic Place Autocomplete request in Places SDK for Android
final FindAutocompletePredictionsRequest newRequest = FindAutocompletePredictionsRequest.builder().setSessionToken(sessionToken).setLocationBias(bias).setTypeFilter(TypeFilter.ESTABLISHMENT).setQuery(query).setCountries("IN").build();
// Perform autocomplete predictions request
placesClient.findAutocompletePredictions(newRequest).addOnSuccessListener((response) -> {
List<AutocompletePrediction> predictions = response.getAutocompletePredictions();
adapter.setPredictions(predictions);
progressBar.setIndeterminate(false);
viewAnimator.setDisplayedChild(predictions.isEmpty() ? 0 : 1);
}).addOnFailureListener((exception) -> {
progressBar.setIndeterminate(false);
if (exception instanceof ApiException) {
ApiException apiException = (ApiException) exception;
Log.e(TAG, "Place not found: " + apiException.getStatusCode());
}
});
}
use of com.google.android.libraries.places.api.Places 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