2

I am trying to send a user query to Google Maps Geocoding API, and restrict it to the countries that my service will be operating in. If I just want results from the UK, then the following query works when searching for quay:

https://maps.googleapis.com/maps/api/place/autocomplete/json?key=$apiKey&input=quay&language=en-gb&location=0,0&radius=50000&components=country:uk

If I want to restrict the results to just France then the following works:

https://maps.googleapis.com/maps/api/place/autocomplete/json?key=$apiKey&input=quay&language=en-gb&location=0,0&radius=50000&components=country:uk

According to https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering A filter consists of a list of component:value pairs separated by a pipe (|). So in order to search both the UK and France, I thought the following would work:

https://maps.googleapis.com/maps/api/place/autocomplete/json?key=$apiKey&input=quay&language=en-gb&location=0,0&radius=50000&components=country:uk|fr

But it doesn't, instead it returns the following:

{ "predictions": [], "status": "INVALID_REQUEST" }

I've also tried changing the components piece at the end of the URL to components=country:uk|country:fr. This appears to work, but all it is doing is searching whatever is the last country:value on the URL.

As far as I can tell, my options are:

  • Search the UK and France separately, and then combine the results. This will require twice as many calls and will go up with each country added. I will also need to determine how to weight the results.
  • Remove the component restriction so that I get all results from around the world, and filter the answers myself to the UK and France. There's a good chance that the results that the Geocoding API returns will result in no results to display.

How can I make one call to return results just restricted to the UK and France? Is this even possible?

Arthur
  • 1,332
  • 2
  • 19
  • 39
  • Check this answer it helps me https://stackoverflow.com/a/42901194/3933302 – Sourabh Sharma Jun 16 '17 at 07:20
  • 1
    Thanks @SourabhSharma, Google have updated the API so that you can now do this. – Arthur Jun 23 '17 at 10:53
  • @Arthur This functionality is still broken, especially using a PR zipcode as the address and using filters for both components of country:us and country:pr. Additionally the responses behave different depending on which US zipcode is passed. Sometimes no results are returned when using two countries but will return results using the same address and one country. – Joseph Persico Feb 09 '21 at 19:36

1 Answers1

2

This is currently not possible in 1 call, see https://code.google.com/p/gmaps-api-issues/issues/detail?id=4233

StryKaizer
  • 136
  • 3