如何将Google Geocode查询限制在多个国家/地区? [英] How do I restrict a Google Geocode query to multiple countries?
问题描述
我正在尝试向Google Maps Geocoding API发送用户查询,并将其查询限制在我的服务将在其运行的国家/地区.如果我只想要英国的结果,则在搜索
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
根据 https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering A filter consists of a list of component:value pairs separated by a pipe (|).
因此,为了同时搜索英国和法国,我认为可以使用以下方法:
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"
}
{
"predictions": [],
"status": "INVALID_REQUEST"
}
我还尝试将URL末尾的组件部分更改为components=country:uk|country:fr
.这似乎可行,但是它所要做的就是搜索URL上最后一个country:value
.
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:
- 分别搜索英国和法国,然后将结果合并.这将需要两倍的通话量,并且会增加每个国家/地区的通话次数.我还需要确定如何权衡结果.
- 删除组件限制,以便获得世界各地的所有结果,并自行过滤出英国和法国的答案. Geocoding API返回的结果很有可能导致没有结果显示.
如何拨打电话以返回仅限于英国和法国的结果?这有可能吗?
How can I make one call to return results just restricted to the UK and France? Is this even possible?
推荐答案
This is currently not possible in 1 call, see https://code.google.com/p/gmaps-api-issues/issues/detail?id=4233
这篇关于如何将Google Geocode查询限制在多个国家/地区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!