react-places-autocomplete icon indicating copy to clipboard operation
react-places-autocomplete copied to clipboard

Settings types in options to cities not working

Open quachsimon opened this issue 7 years ago • 9 comments

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?

quachsimon avatar Oct 25 '17 20:10 quachsimon

Same problem for me.

cicerone-f avatar Nov 15 '17 12:11 cicerone-f

@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)']

quachsimon avatar Nov 15 '17 17:11 quachsimon

I am having this issue trying to limit the types to address.

searchOptions={{ types: ["address"], country: ["ca", "us"] }}

Is returning INVALID_REQUESTS

rfreethy avatar Aug 24 '18 15:08 rfreethy

@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

mostlyharmless2024 avatar Mar 15 '19 04:03 mostlyharmless2024

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 avatar May 31 '19 23:05 itsmhuang

@itsmhuang , are you still seeing this issue? I am.

cmacdonnacha avatar Jul 08 '19 18:07 cmacdonnacha

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)']
  }}
>

m-jabrane avatar Nov 12 '19 10:11 m-jabrane

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): image

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:

image

edit, here's Maui without any "types" restriction: image

mostlyharmless2024 avatar Nov 30 '19 18:11 mostlyharmless2024

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

nescroft avatar Feb 09 '21 17:02 nescroft