Seleccione sus preferencias de cookies

Usamos cookies esenciales y herramientas similares que son necesarias para proporcionar nuestro sitio y nuestros servicios. Usamos cookies de rendimiento para recopilar estadísticas anónimas para que podamos entender cómo los clientes usan nuestro sitio y hacer mejoras. Las cookies esenciales no se pueden desactivar, pero puede hacer clic en “Personalizar” o “Rechazar” para rechazar las cookies de rendimiento.

Si está de acuerdo, AWS y los terceros aprobados también utilizarán cookies para proporcionar características útiles del sitio, recordar sus preferencias y mostrar contenido relevante, incluida publicidad relevante. Para aceptar o rechazar todas las cookies no esenciales, haga clic en “Aceptar” o “Rechazar”. Para elegir opciones más detalladas, haga clic en “Personalizar”.

Use SearchText with an AWS SDK

Modo de enfoque
Use SearchText with an AWS SDK - AWS SDK Code Examples
Esta página no se ha traducido a su idioma. Solicitar traducción

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

The following code example shows how to use SearchText.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/** * Searches for a place using the provided search query and prints the detailed information of the first result. * * @param searchQuery the search query to be used for the place search (ex, coffee shop) */ public CompletableFuture<Void> searchText(String searchQuery) { double latitude = 37.7749; // San Francisco double longitude = -122.4194; List<Double> queryPosition = List.of(longitude, latitude); SearchTextRequest request = SearchTextRequest.builder() .queryText(searchQuery) .biasPosition(queryPosition) .build(); return getGeoPlacesClient().searchText(request) .thenCompose(response -> { if (response.resultItems().isEmpty()) { logger.info("No places found."); return CompletableFuture.completedFuture(null); } // Get the first place ID String placeId = response.resultItems().get(0).placeId(); logger.info("Found Place with id: " + placeId); // Fetch detailed info using getPlace GetPlaceRequest getPlaceRequest = GetPlaceRequest.builder() .placeId(placeId) .build(); return getGeoPlacesClient().getPlace(getPlaceRequest) .thenAccept(placeResponse -> { logger.info("Detailed Place Information:"); logger.info("Name: " + placeResponse.placeType().name()); logger.info("Address: " + placeResponse.address().label()); if (placeResponse.foodTypes() != null && !placeResponse.foodTypes().isEmpty()) { logger.info("Food Types:"); placeResponse.foodTypes().forEach(foodType -> { logger.info(" - " + foodType); }); } else { logger.info("No food types available."); } logger.info("-------------------------"); }); }) .exceptionally(exception -> { Throwable cause = exception.getCause(); if (cause instanceof software.amazon.awssdk.services.geoplaces.model.ValidationException) { throw new CompletionException("A validation error occurred: " + cause.getMessage(), cause); } throw new CompletionException("Error performing place search", exception); }); }
  • For API details, see SearchText in AWS SDK for Java 2.x API Reference.

SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/** * Searches for a place using the provided search query and prints the detailed information of the first result. * * @param searchQuery the search query to be used for the place search (ex, coffee shop) */ public CompletableFuture<Void> searchText(String searchQuery) { double latitude = 37.7749; // San Francisco double longitude = -122.4194; List<Double> queryPosition = List.of(longitude, latitude); SearchTextRequest request = SearchTextRequest.builder() .queryText(searchQuery) .biasPosition(queryPosition) .build(); return getGeoPlacesClient().searchText(request) .thenCompose(response -> { if (response.resultItems().isEmpty()) { logger.info("No places found."); return CompletableFuture.completedFuture(null); } // Get the first place ID String placeId = response.resultItems().get(0).placeId(); logger.info("Found Place with id: " + placeId); // Fetch detailed info using getPlace GetPlaceRequest getPlaceRequest = GetPlaceRequest.builder() .placeId(placeId) .build(); return getGeoPlacesClient().getPlace(getPlaceRequest) .thenAccept(placeResponse -> { logger.info("Detailed Place Information:"); logger.info("Name: " + placeResponse.placeType().name()); logger.info("Address: " + placeResponse.address().label()); if (placeResponse.foodTypes() != null && !placeResponse.foodTypes().isEmpty()) { logger.info("Food Types:"); placeResponse.foodTypes().forEach(foodType -> { logger.info(" - " + foodType); }); } else { logger.info("No food types available."); } logger.info("-------------------------"); }); }) .exceptionally(exception -> { Throwable cause = exception.getCause(); if (cause instanceof software.amazon.awssdk.services.geoplaces.model.ValidationException) { throw new CompletionException("A validation error occurred: " + cause.getMessage(), cause); } throw new CompletionException("Error performing place search", exception); }); }
  • For API details, see SearchText in AWS SDK for Java 2.x API Reference.

PrivacidadTérminos del sitioPreferencias de cookies
© 2025, Amazon Web Services, Inc o sus afiliados. Todos los derechos reservados.