Fla*_*ass 1 google-maps google-places-api google-places-autocomplete
我正在制作一个自定义自动完成字段,我的目标是仅获取一个国家/地区的城市。
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=amsterdam&inputtype=textquery&types=(cities)&fields=geometry,name&language=nl&key=APIKEY
我读过有关约束特定国家/地区的组件限制。如何在请求中包含参数?
添加参数&componentRestrictions=nl不起作用。
根据Web 服务的文档,参数为components:
\n\n\n
\n- Components \xe2\x80\x94 您想要将结果限制到的一组位置。目前,您可以使用组件最多过滤 5 个国家/地区。国家/地区必须以两个字符、ISO 3166-1 Alpha-2 兼容的国家/地区代码形式传递。例如:components=country:fr 会将您的结果限制为法国境内的地区。多个国家/地区必须作为多个国家/地区:XX 过滤器传递,并使用竖线字符 (|) 作为分隔符。例如: Components=country:us|country:pr|country:vi|country:gu|country:mp 会将您的结果限制为美国境内及其非建制的有组织领土。
\n
例子:components=country:nl
完整网址:
\nhttps://maps.googleapis.com/maps/api/place/autocomplete/json?input=amsterdam&inputtype=textquery&types=(cities)&fields=geometry,name&language=nl&components=country:nl&key=APIKEY\nRun Code Online (Sandbox Code Playgroud)\n