Does your application include an address form, such as the shipping address for an online order, a credit card billing address, or a ridesharing booking form? Autocomplete can help users supply the details.
The Place Autocomplete Address Form sample captures selected address components from the Google Places database, and uses them to populate an address form.
Since this sample only requires a place address in a structured format, the
sample code uses just one place data field: address_components
. The requested
place data fields affect the
cost of each request. You can specify
which place data fields to return by calling
Autocomplete.setFields()
,
and specifying one or more
place data fields.
The address components in this sample are based on a typical address format.
Note that you might need to use a different set of components to align with the
postal address formats used in some regions. For example, the sample code
selects the locality
component, which often represents the city part of the
address. Examples of how components can differ include:
- In the UK and in Sweden, the component to display the city is
postal_town
. - In Japan, components differ across prefectures.
- Brooklyn and other parts of New York City do not include the city as part of
the address. Instead, they use
sublocality_level_1
.
When the user selects an address from the pick list, your application can populate the address form.
For more information, see Places Autocomplete widget.
TypeScript
// This sample uses the Places Autocomplete widget to: // 1. Help the user select a place // 2. Retrieve the address components associated with that place // 3. Populate the form fields with those address components. // This sample requires the Places library, Maps JavaScript API. // Include the libraries=places parameter when you first load the API. // For example: