react-places-autocomplete
react-places-autocomplete copied to clipboard
Settings types in options to cities not working
I am trying to set the types
in the options parameters to limit the search to just cities.
const options = {
location: new google.maps.LatLng(85, -180),
radius: 5000,
types: ['cities']
}
When I do this, I receive INVALID_REQUESTS
from the onError
callback.
I am following the docs and those are one of the options.
What am I missing?
Same problem for me.
@cicer1 It wasn't obvious but, I had to wrap it around parentheses exactly like the docs (cities)
so you would have to put it like so: types: ['(cities)']
I am having this issue trying to limit the types to address.
searchOptions={{ types: ["address"], country: ["ca", "us"] }}
Is returning INVALID_REQUESTS
@cicer1 It wasn't obvious but, I had to wrap it around parentheses exactly like the docs
(cities)
so you would have to put it like so:types: ['(cities)']
Serious thanks for this one, great catch, wish google was little more clear about the syntax...
For others looking for the actual reference on this:
https://developers.google.com/places/supported_types#table3
This is still broken or broken again. Setting types: ['(cities)']
doesn't limit the search results to cities, the search results still returns all types.
@itsmhuang , are you still seeing this issue? I am.
I don't know why! but if you create a variable with customized parameters and then give that variable to the searchOptions
parameter it's not gonna work. I had to give these customized parameters directly in the component like:
<PlacesAutocomplete
onChange={this.Change}
onSelect={this.handleSelect}
searchOptions={{
componentRestrictions: {
country: ['us'],
},
types: ['(cities)']
}}
>
Yeah this is definitely not working well again :( and @m-jabrane 's solution isn't working for me either, using that exact code my autocomplete isn't filtering by cities only OR by country (US):
However, removing the "types" property all together does appear to make the country filter work... :/
We're considering just allowing all "places" through anyway... cities only has just been a headache :/ especially in rural areas, and even Hawaii:
edit, here's Maui without any "types" restriction:
i was able to get it working for REACT NATIVE with query={{ types: '(cities)',}} (no array) using https://github.com/FaridSafi/react-native-google-places-autocomplete