Beta
Search SDK for Android

Address Autofill

Suppose you need a user to enter a valid home or delivery address. They typically need to do this during the registration or checkout process, where making the entry process as smooth as possible can help you prevent churn. This is where enabling users to fill in the address form by entering only a few characters is the most beneficial.

User experience

  1. Whenever it’s time to fill in the address in your app, the user is presented with a form. The top field in the form is focused for input.
  2. When the user starts typing, a list of valid, matching addresses is displayed, with the addresses closest to the user presented first.
  3. The user taps one of the suggested addresses and the form fields are filled.
  4. Your app shows the map with a pin placed for the selected address, which enables the user to visually confirm that they selected the correct address.
  5. Users also have the option of adding a comment for a housing unit, specific delivery instructions, or confirm the address they otherwise would need to type in manually.

We have a ready-made sample app that you can try in Android Studio with Address Autofill and other scenarios. We encourage you to install and try it for yourself.

example
Full example of Address Form Autofill

Learn how to integrate Search SDK Address Autofill with UI for suggestions, filled-in form components, and a visual map confirmation (includes Maps SDK) in a sample app.

Integration

Address Autofill provides coroutine-based API. In the following integration steps, we assume that you are familiar with the Kotlin coroutines and your Android project has Kotlin-ktx dependencies added. See the Kotlin coroutines guide for more information.

guide
Installation guide

Before using any of Mapbox's Search products, you need to do some common installation steps. Please follow this guide, then continue with the steps below.

  1. Get instance of AddressAutofill:
val addressAutofill = AddressAutofill.create(mapboxAccessToken)
  1. Add a request for input from the user:
val query = receivedInput
lifecycleScope.launchWhenCreated {
    val response = addressAutofill.suggestions(query, AddressAutofillOptions())
    when (response) {
        is AddressAutofillResponse.Suggestions -> {
             showSuggestions(response.suggestions)
        }
        ...
    }
}
  1. Process results to fill in the UI fields:
val suggestion = pickSuggestion(response.suggestions)
val resultAddress = suggestion.result().address
placeField.setText(resultAddress.place)
countryField.setText(resultAddress.country)
glossary
API Reference

For more information, see the full API reference for the Android Search SDK.

Why use SDK?

If your primary use case is targeted to mobile devices (iOS & Android), we strongly encourage you to use our Search SDK. With Search SDK, you get:

Stable SDK API

By defining our use cases, we aim to support the same interface for longer even if the underlying implementation changes. This means bumping the SDK version fixes all issues you might encounter without requiring you to rework the app or its integration code.

Fewer lines of code

Developers can get up and running with a few lines of straightforward code to start the SDK, get address suggestions, and fill in the results. See for yourself, it’s readable, maintainable, and error-proof.

Protecting against errors and pitfalls

Having a ready-made integration example enables you to experiment faster and avoid common pitfalls of using API in a non-preferred way.

Drop-in UI support
Experimental

Have no need for custom UI and ready to get started? We have you covered with an easy-to-blend UI that doesn’t require extensive binding to current components and navigation flow.


Want to use Autofill on your website?

For using Address Autofill on the web see our Mapbox Search JS SDK.