Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Use SearchText with an AWS SDK

Focus mode
Use SearchText with an AWS SDK - AWS SDK Code Examples

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.

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.