1
votes

I'm trying to restrict search results to a country and heavily bias them to a particular lat/lng (but not restrict).

I'm using the "bounds" field to bias the search results returned by the API to user's location (documentation). This works well, however, I also need to restrict the returned results to a country.

I'm using the "region" field for that but it does not restrict the results to a country and only biases them. I tried using the "componentRestrictions" field to restrict results to a country. This works well, however, the location biasing I set-up initially (with the "bounds" field) seems to stop working (or at least working differently now).

Any ideas on how one might achieve my goal here?

Example

I'm sending a geocoder request for "35 bastion st." with region set to CA (Canada) with bounds set-up to be 2.5 degrees around Vancouver, BC, Canada. There are two search results that can come up: one in Toronto, Ontario, Canada and another in Nanaimo, British Columbia, Canada. I expect the Nanaimo one to come up in this case because it's the closer location and it does. Link: https://maps.googleapis.com/maps/api/geocode/json?address=35%20bastion%20st.&region=CA&bounds=46.7827,-125.6207|51.7827,-120.620&key=AIzaSyD3y1Mk-vZjfgqg1GB_dOWMDo004oY8xus

Now if I have the same request but with the country filter applied I would expect the same result to be returned but that is not what happens. Link: https://maps.googleapis.com/maps/api/geocode/json?address=35%20bastion%20st.&region=CA&bounds=46.7827,-125.6207|51.7827,-120,%20-122.1207&components=country:CA&key=AIzaSyD3y1Mk-vZjfgqg1GB_dOWMDo004oY8xus

Edit:

Corrected second link: https://maps.googleapis.com/maps/api/geocode/json?address=35%20bastion%20st.&bounds=46.7827,-125.6207|51.7827,-120.620&components=country:CA&key=AIzaSyD3y1Mk-vZjfgqg1GB_dOWMDo004oY8xus

1
Please provide a Minimal, Complete, and Verifiable example that allows to reproduce the issue, including example search terms, expected and actual results, and explain why you think that the biasing doesn't work anymore. - MrUpsidown
@MrUpsidown thanks for the response. I added an example query. Please let me know if something is not clear in my example. - Umar Bolatov
I have edited your question with a corrected second link as there was something wrong with your bounds. I don't see a need to use both the region and the country filter so I removed the region as well. I still get the same result (Toronto) which doesn't make much sense... I'll try a few more things. - MrUpsidown
I observe the same behavior using the Geocoder class from the JS API. I have opened an issue about it. Please star the issue in the issue tracker to be notified of any updates! jsfiddle.net/upsidown/cu26svew - MrUpsidown
It seems that the issue was caused by the sythethic Place ID of 35 Bastion st. in Nanaimo (EiozNSBCYXN0aW9uIFN0LCBOYW5haW1vLCBCQyBWOVIgM0ExLCBDYW5hZGEiGhIYChQKEgmD8wBXWKGIVBHqqdKOQhsrxRAj), a workaround can be made though by making the input to "35 Bastion st. Nanaimo". If you experience this in other addresses as well with proper Place ID kindly provide it here :) - Shawn Domingo

1 Answers

1
votes

According to Google this is not a bug (see here: https://issuetracker.google.com/issues/123557217).

According to our engineers, this is working as intended.

The reason being that the country component will take priority when using the two parameters, as the use-cases of the two are entirely different.

Moreover, "35 Bastion st" is very ambiguous and it should be searched using Autocomplete where viewports/bounds can influence the results better.