I want to build a map with a search input. The user should be able to search for zip or city with that input. This appears not so be well documented in the Google Geocoding API or in the Javascript API reference for the Geocoder.
I tried to use the geocode function as follows:
geocode({ address: inputValue })
but this will give results in the whole world.
Then I used the region and the bounds:
geocode({ address: this.value, region: 'XX', bounds: myCountryBounds })
This will still give results from the entire world. (I read on one of the documentation pages that the region
and bounds
are only informative and not strict restrictions, but I cannot find the page anymore.)
Then I used only componentRestrictions
:
geocode({ address: this.value, componentRestrictions: { country: 'XX' })
This now gives me only results in country XX
. But it also gives me street and company names.
Now I want the search only to match zips and cities. Because if I search for 2000
I find lots of company names that have 2000
in their names. So how can I make sure the search is only performed in zips and city names?