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
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
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
- 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
When the user selects an address from the pick list, your application can populate the address form.
For more information, see Places Autocomplete widget.
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
Other samples can be tried by switching to any branch beginning with
git checkout sample-SAMPLE_NAME