Google API - Autocomplete does not have zip code

2

I'm trying to use Google services to get mailing. The idea is to enter the address or zip and load the data street, neighborhood, zip, city and state.

I've been able to get most of the data, but the zip is not being returned in the output. Here is the service call and the result (I changed the key to remove it, it will not work, but the URI is ok):

link

    {
   "predictions" : [
      {
         "description" : "Avenida Embaixador Abelardo Bueno - Barra da Tijuca, Rio de Janeiro - RJ, Brasil",
         "id" : "31fc7076c2289ecf1b100f0a769553d5341ac002",
         "matched_substrings" : [
            {
               "length" : 33,
               "offset" : 0
            }
         ],
         "place_id" : "ElBBdmVuaWRhIEVtYmFpeGFkb3IgQWJlbGFyZG8gQnVlbm8gLSBCYXJyYSBkYSBUaWp1Y2EsIFJpbyBkZSBKYW5laXJvIC0gUkosIEJyYXNpbA",
         "reference" : "CmRUAAAAkQ98koLpBb_VEBonelaZ8iCxYEHtJp0sDeH4gtBzgEnkOs4hpwI7Jaxd0Nq7ZAo1pfsWy9YRLWFkIz0D4EyAZC6ncoK-rQ-dTr9lMWVeFqhZTK50x-zweb3LFcb_zAJDEhD7GsVJdIBYX0_ldipY-272GhSqcdx6p9Ml9BgchUoHct1wglHwqQ",
         "structured_formatting" : {
            "main_text" : "Avenida Embaixador Abelardo Bueno",
            "main_text_matched_substrings" : [
               {
                  "length" : 33,
                  "offset" : 0
               }
            ],
            "secondary_text" : "Barra da Tijuca, Rio de Janeiro - RJ, Brasil"
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Avenida Embaixador Abelardo Bueno"
            },
            {
               "offset" : 36,
               "value" : "Barra da Tijuca"
            },
            {
               "offset" : 53,
               "value" : "Rio de Janeiro"
            },
            {
               "offset" : 70,
               "value" : "RJ"
            },
            {
               "offset" : 74,
               "value" : "Brasil"
            }
         ],
         "types" : [ "route", "geocode" ]
      }
   ],
   "status" : "OK"

Is the zip code not returned? Is there any parameter that determines that the zip code needs to be included?

    
asked by anonymous 18.12.2017 / 12:43

1 answer

2

The problem with this approach is that Google location data does not always have the zip code, as you may have noticed.

So, to work with zip codes, suggest the use of Web Services as the ViaCep that has a base of gigantic data with the CEPs of all Brazil.

Unfortunately, you will have to get the information, update the fields and do manual validations, but the Web Service function is quite simple ...

Just access the URL with the address and you will have the zip code in return.

  

link

[
  {
    "cep": "91790-072",
    "logradouro": "Rua Domingos José Poli",
    "complemento": "",
    "bairro": "Restinga",
    "localidade": "Porto Alegre",
    "uf": "RS",
    "unidade": "",
    "ibge": "4314902",
    "gia": ""
  }
]       

It also works in reverse: you enter the zip code and the service returns address details.

  

link

{
  "cep": "01001-000",
  "logradouro": "Praça da Sé",
  "complemento": "lado ímpar",
  "bairro": "Sé",
  "localidade": "São Paulo",
  "uf": "SP",
  "unidade": "",
  "ibge": "3550308",
  "gia": "1004"
}

For cases where a street can have more than one ZIP code, ViaCep will return an array with all ZIP codes available from that street:

  

link

[
  {
    "cep": "01311-909",
    "logradouro": "Avenida Paulista",
    "complemento": "491",
    "bairro": "Bela Vista",
    "localidade": "São Paulo",
    "uf": "SP",
    "unidade": "",
    "ibge": "3550308",
    "gia": "1004"
  },
  {
    "cep": "01311-905",
    "logradouro": "Avenida Paulista",
    "complemento": "347",
    "bairro": "Bela Vista",
    "localidade": "São Paulo",
    "uf": "SP",
    "unidade": "",
    "ibge": "3550308",
    "gia": "1004"
  },
  {
    "cep": "01310-000",
    "logradouro": "Avenida Paulista",
    "complemento": "até 610 - lado par",
    "bairro": "Bela Vista",
    "localidade": "São Paulo",
    "uf": "SP",
    "unidade": "",
    "ibge": "3550308",
    "gia": "1004"
  },
  {
    "cep": "01310-933",
    "logradouro": "Avenida Paulista",
    "complemento": "2444",
    "bairro": "Bela Vista",
    "localidade": "São Paulo",
    "uf": "SP",
    "unidade": "",
    "ibge": "3550308",
    "gia": "1004"
  }
...
    
18.12.2017 / 15:27