angular-google-maps with places autocomplete - need of custom componentRestrictions (not only country as provided)?

170 views Asked by At

everyone!

I am using angular-google-maps /@angular/google-maps": "13.3.9"/ in an Angular app /angular v - 13/, and everything was great until I encountered the following problem (hope with some proper solution). I have an input field in the html of a component where the user types in and selects a place, where autocomplete dropdown suggests the proper options, because I am using in .ts file: this.autocomplete = new google.maps.places.Autocomplete(this.inputElement, { componentRestrictions: { country: 'US' } });.

So great, I only list places in the USA, but now I want to show only, say, states, or even better, only cities which I want. (I mean I have a list of cities, every city with its state) and I want the user to be able to select places only there in the autocomplete input. From all the docs and examples with similar question I read I have found nothing so far. Has somebody already encountered this problem and found a solution? I thought of listening for this "place_changed" event and when triggered to somehow custom filter the values, but I do not have a clear view of how to accomplish it.

Great if you could help! :)

0

There are 0 answers