Google Places API,使用邮政编码自动完成
Posted
技术标签:
【中文标题】Google Places API,使用邮政编码自动完成【英文标题】:Google places API, autocomplete with postal code 【发布时间】:2014-09-02 08:29:59 【问题描述】:所以我正在尝试使用城市(在比利时)实现 AutoCompleteTextView。
这是我调用的网址:
https://maps.googleapis.com/maps/api/place/autocomplete/json?components=country:be&types=(cities)&language=nl&key=INSERTKEY&input=Sint-Niklaas
这是我收到的结果
"html_attributions" : [],
"result" :
"address_components" : [
"long_name" : "Sint-Niklaas",
"short_name" : "Sint-Niklaas",
"types" : [ "locality", "political" ]
,
"long_name" : "Oost-Vlaanderen",
"short_name" : "OV",
"types" : [ "administrative_area_level_2", "political" ]
,
"long_name" : "Vlaams Gewest",
"short_name" : "Vlaams Gewest",
"types" : [ "administrative_area_level_1", "political" ]
,
"long_name" : "België",
"short_name" : "BE",
"types" : [ "country", "political" ]
],
"adr_address" : "\u003cspan class=\"locality\"\u003eSint-Niklaas\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eBelgië\u003c/span\u003e",
"formatted_address" : "Sint-Niklaas, België",
"geometry" :
"location" :
"lat" : 51.1558839,
"lng" : 4.154440999999999
,
"viewport" :
"northeast" :
"lat" : 51.2078001,
"lng" : 4.22161
,
"southwest" :
"lat" : 51.12957000000001,
"lng" : 3.985439999999999
,
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "b58d02f8e9b9e23b20672df537655b0db8df49c4",
"name" : "Sint-Niklaas",
"place_id" : "ChIJbTeC4aKOw0cRjfRXrcMzDNY",
"reference" : "CoQBeAAAANQfy31Z2rrxWOIYEkCCVh-jrEdi-WRLSJdxwO2SnZPtrumlfQdtzwW3CwFZ9qP8hgNmVYO9HySMMQ28dWm45YYnW-NJ2XmNepK0keyPOlZ6BAyeDhTa56aE-3cqYUHE6GE_h70kw6uh-cWuImPJ64k-Pc7YgX6EoZYFIvO3PexDEhAkMx1ebDvOUVUcLK8XL-MiGhQkYJEvxLQHO0qz72wpSmdqlDkrtA",
"scope" : "GOOGLE",
"types" : [ "locality", "political" ],
"url" : "https://maps.google.com/maps/place?q=Sint-Niklaas,+Belgi%C3%AB&ftid=0x47c38ea2e182376d:0xd60c33c3ad57f48d",
"vicinity" : "Sint-Niklaas"
,
"status" : "OK"
但我了解到您可以使用地点详细信息 API 获取地点详细信息,因此我尝试搜索收到的地点 ID:
https://maps.googleapis.com/maps/api/place/details/json?INSERTKEY&placeid=ChIJbTeC4aKOw0cRjfRXrcMzDNY
这会返回一大堆数据,但没有邮政编码:
"html_attributions" : [],
"result" :
"address_components" : [
"long_name" : "Sint-Niklaas",
"short_name" : "Sint-Niklaas",
"types" : [ "locality", "political" ]
,
"long_name" : "Oost-Vlaanderen",
"short_name" : "OV",
"types" : [ "administrative_area_level_2", "political" ]
,
"long_name" : "Vlaams Gewest",
"short_name" : "Vlaams Gewest",
"types" : [ "administrative_area_level_1", "political" ]
,
"long_name" : "België",
"short_name" : "BE",
"types" : [ "country", "political" ]
],
"adr_address" : "\u003cspan class=\"locality\"\u003eSint-Niklaas\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eBelgië\u003c/span\u003e",
"formatted_address" : "Sint-Niklaas, België",
"geometry" :
"location" :
"lat" : 51.1558839,
"lng" : 4.154440999999999
,
"viewport" :
"northeast" :
"lat" : 51.2078001,
"lng" : 4.22161
,
"southwest" :
"lat" : 51.12957000000001,
"lng" : 3.985439999999999
,
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "b58d02f8e9b9e23b20672df537655b0db8df49c4",
"name" : "Sint-Niklaas",
"place_id" : "ChIJbTeC4aKOw0cRjfRXrcMzDNY",
"reference" : "CoQBeAAAANQfy31Z2rrxWOIYEkCCVh-jrEdi-WRLSJdxwO2SnZPtrumlfQdtzwW3CwFZ9qP8hgNmVYO9HySMMQ28dWm45YYnW-NJ2XmNepK0keyPOlZ6BAyeDhTa56aE-3cqYUHE6GE_h70kw6uh-cWuImPJ64k-Pc7YgX6EoZYFIvO3PexDEhAkMx1ebDvOUVUcLK8XL-MiGhQkYJEvxLQHO0qz72wpSmdqlDkrtA",
"scope" : "GOOGLE",
"types" : [ "locality", "political" ],
"url" : "https://maps.google.com/maps/place?q=Sint-Niklaas,+Belgi%C3%AB&ftid=0x47c38ea2e182376d:0xd60c33c3ad57f48d",
"vicinity" : "Sint-Niklaas"
,
"status" : "OK"
我做错了什么?
【问题讨论】:
【参考方案1】:如果您正在尝试查找城市名称和邮政编码,则会回复here
【讨论】:
以上是关于Google Places API,使用邮政编码自动完成的主要内容,如果未能解决你的问题,请参考以下文章
如何让 Google 地图“Places API”返回邮政编码信息?
Google Places API 不会返回大城市或中心的邮政编码。我该如何解决?
使用 Google Places Autocomplete API 时空间不工作
如何正确限制对 Android 和 iOS 应用程序(用 Flutter 编写)的 Google 地图(地点、地理编码)API 调用?