-
Notifications
You must be signed in to change notification settings - Fork 943
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
Enable limiting location autocomplete to a certain country #1002
Conversation
src/config.js
Outdated
// Limit location autocomplete to a one or more countries | ||
// using ISO 3166 alpha 2 country codes separated by commas. | ||
// If you don't want to limit the autocomplete you can comment out this value. | ||
limit: ['AU'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe changing the name to countryLimit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And don't leave this countryLimit
active!
src/util/googleMaps.js
Outdated
* | ||
* @return {Promise<{ search, predictions[] }>} - Promise of an object | ||
* with the original search query and an array of | ||
* `google.maps.places.AutocompletePrediction` objects | ||
*/ | ||
export const getPlacePredictions = (search, sessionToken) => | ||
export const getPlacePredictions = (search, sessionToken, restriction) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is probably better to rename this to searchConfigurations
(or something like that) since there are more configurations that could be passed in than just componentRestrictions
const limitCountriesMaybe = config.maps.search.limit | ||
? { country: config.maps.search.limit } | ||
: {}; | ||
const restriction = { componentRestrictions: { ...limitCountriesMaybe } }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not send a key componentRestrictions
if there is no countryLimit
set.
const limitCountriesMaybe = config.maps.search.limit
? {
componentRestrictions: {
country: config.maps.search.limit,
},
}
: {};
Then limitCountriesMaybe
could be spread directly to the call:
return getPlacePredictions(search, this.getSessionToken(), limitCountriesMaybe).then(results => {
8ff13c8
to
8fab542
Compare
8fab542
to
6ff26d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Limit location autocomplete by adding an optional country parameter to geocoding call in both Mapbox and Google Maps integrations. Variable used to enable this is
config.maps.search.limit
and it can be found fromconfig.js
file. The same variable works for Mapbox and Google Maps integrations.Also updated Mapbox SDK to version 0.5.0.