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
.
Clone Sample
Git and Node.js are required to run this sample locally. Follow these
instructions
to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.
git clone -b sample-places-autocomplete-addressform https://github.com/googlemaps/js-samples.git
cd js-samples
npm i
npm start
Other samples can be tried by switching to any branch beginning with
sample-
SAMPLE_NAME
.
git checkout sample-
SAMPLE_NAME
npm i
npm start