### Search by text

The `Amplify.Geo.searchByText()` API enables you to search for places or points of interest by free-form text, such as an address, name, city, or region.

<BlockSwitcher>
<Block name="Java">

```java
String searchQuery = "Amazon Go";
Amplify.Geo.searchByText(searchQuery,
    result -> {
        for (final Place place : result.getPlaces()) {
            Log.i("MyAmplifyApp", place.toString());
        }
    },
    error -> Log.e("MyAmplifyApp", "Failed to search for " + searchQuery, error)
);
```

</Block>
<Block name="Kotlin - Callbacks">

```kotlin
val searchQuery = "Amazon Go"
Amplify.Geo.searchByText(searchQuery,
    {
        for (place in it.places) {
            Log.i("MyAmplifyApp", place.toString())
        }
    },
    { Log.e("MyAmplifyApp", "Failed to search for $searchQuery", it) }
)
```

</Block>
<Block name="Kotlin - Coroutines">

```kotlin
val searchQuery = "Amazon Go"
try {
    val result = Amplify.Geo.searchByText(searchQuery)
    for (place in result.places) {
        Log.i("MyAmplifyApp", place.toString())
    }
} catch (error: GeoException) { 
    Log.e("MyAmplifyApp", "Failed to search for $searchQuery", it)
}
```

</Block>
<Block name="RxJava">

```java
String searchQuery = "Amazon Go";
RxAmplify.Geo.searchByText(searchQuery).subscribe(
    result -> {
        for (final Place place : result.getPlaces()) {
            Log.i("MyAmplifyApp", place.toString());
        }
    },
    error -> Log.e("MyAmplifyApp", "Failed to search for " + searchQuery, error)
);
```

</Block>
</BlockSwitcher>

Restrict your search results by specifying following parameters inside `GeoSearchByTextOptions`:
- `countries` - to limit the search results to given countries. Follows [ISO Alpha-3 country codes](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3). (defaults to "USA")
- `maxResults` - to limit the maximum result set (defaults to 50)
- `searchArea`
  - `near` - to act as the search origination location
  - `within` - to limit the area to search inside of

<BlockSwitcher>
<Block name="Java">

```java
Coordinates position = new Coordinates(47.6153, -122.3384);
GeoSearchByTextOptions options = GeoSearchByTextOptions.builder()
    .maxResults(10)
    .searchArea(SearchArea.near(position))
    .countries(Collections.singletonList(CountryCode.USA))
    .build();
```

</Block>
<Block name="Kotlin - Callbacks">

```kotlin
val position = Coordinates(47.6153, -122.3384)
val options = GeoSearchByTextOptions.builder()
    .maxResults(10)
    .searchArea(SearchArea.near(position))
    .countries(listOf(CountryCode.USA))
    .build()
```

</Block>
<Block name="Kotlin - Coroutines">

```kotlin
val position = Coordinates(47.6153, -122.3384)
val options = GeoSearchByTextOptions.builder()
    .maxResults(10)
    .searchArea(SearchArea.near(position))
    .countries(listOf(CountryCode.USA))
    .build()
```

</Block>
<Block name="RxJava">

```java
Coordinates position = new Coordinates(47.6153, -122.3384);
GeoSearchByTextOptions options = GeoSearchByTextOptions.builder()
    .maxResults(10)
    .searchArea(SearchArea.near(position))
    .countries(Collections.singletonList(CountryCode.USA))
    .build();
```

</Block>
</BlockSwitcher>
