简体   繁体   中英

Google places API, autocomplete with postal code

So I'm trying to implement a AutoCompleteTextView with cities (in Belgium).

This is the url I call :

https://maps.googleapis.com/maps/api/place/autocomplete/json?components=country:be&types=(cities)&language=nl&key=INSERTKEY&input=Sint-Niklaas

This is the result I receive

{
   "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"
}

But I've read that you could get place details with the place details API, so I've tried to search on the placeid I received:

https://maps.googleapis.com/maps/api/place/details/json?INSERTKEY&placeid=ChIJbTeC4aKOw0cRjfRXrcMzDNY

This returns a whole bunch of data but no postal code:

{
   "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"
}

What am I doing wrong?

如果您正在尝试查找城市名称和邮政编码,请在此处回答

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM