How do I restrict a Google Geocode query to multiple countries?

早过忘川 提交于 2019-12-12 17:05:47

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/33387993/how-do-i-restrict-a-google-geocode-query-to-multiple-countries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!