Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better support for non-US cities in address autocomplete by pulling in postal_town #16567

Merged
merged 3 commits into from
Mar 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/components/AddressSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ const AddressSearch = (props) => {
const {
street_number: streetNumber,
route: streetName,
locality: city,
sublocality: cityFallback, // Some locations only return sublocality instead of locality
locality,
sublocality,
postal_town: postalTown,
postal_code: zipCode,
administrative_area_level_1: state,
country,
Expand All @@ -115,6 +116,7 @@ const AddressSearch = (props) => {
route: 'long_name',
locality: 'long_name',
sublocality: 'long_name',
postal_town: 'long_name',
postal_code: 'long_name',
administrative_area_level_1: 'short_name',
country: 'short_name',
Expand All @@ -130,7 +132,12 @@ const AddressSearch = (props) => {

const values = {
street: props.value ? props.value.trim() : '',
city: city || cityFallback,

// When locality is not returned, many countries return the city as postalTown (e.g. 5 New Street
jjcoffee marked this conversation as resolved.
Show resolved Hide resolved
// Square, London), otherwise as sublocality (e.g. 384 Court Street Brooklyn). If postalTown is
// returned, the sublocality will be a city subdivision so shouldn't take precedence (e.g.
// Salagatan, Upssala, Sweden).
city: locality || postalTown || sublocality,
zipCode,
state,
country: '',
Expand Down