Address search in google maps and return zip with 5 digits

0

I made a dragger in google maps, that moving the marker to the street, it returns all the data of the street / av / travessa etc.

My question is:

  • Has some address that returns 5 digits, is this normal?
  • How do you generally handle the 5-digit zip code address?]
  

Example: Looking for this address: Avenida Alexandre Mackenzie
  It returns me this zip: 05322

What do I do wrong in the search?

function geocodePosition(pos) {
        geocoder = new google.maps.Geocoder();
        geocoder.geocode({latLng: pos}, function(responses) {
            if (responses && responses.length > 0) {
                marker.formatted_address = responses[0].formatted_address;
                console.log(responses[0]);
                for(var i in responses[0].address_components){
                    if (typeof(responses[0].address_components[i]) === "object" && responses[0].address_components[i].types[0] == "street_number") {
                        if (typeof responses[0].address_components[i].short_name != undefined){
                            $('#end_numero').val(responses[0].address_components[i].short_name);
                        }
                    } else if (typeof(responses[0].address_components[i]) === "object" && responses[0].address_components[i].types[0] == "route") {
                        if (typeof responses[0].address_components[i].long_name != undefined){
                            $('#end_rua').val(String(responses[0].address_components[i].long_name.toUpperCase()).replace("'", ""));
                        }
                    } else if (typeof(responses[0].address_components[i]) === "object" && responses[0].address_components[i].types[2] == "sublocality_level_1") {
                        if (typeof responses[0].address_components[i].short_name != undefined){
                            $('#end_bairro').val(String(responses[0].address_components[i].short_name.toUpperCase()).replace("'", "").substring(0,30));
                        }
                    } else if (typeof(responses[0].address_components[i]) === "object" && responses[0].address_components[i].types[0] == "locality") {
                        if (typeof responses[0].address_components[i].long_name != undefined){
                            $('#end_cidade').val(responses[0].address_components[i].long_name.toUpperCase());
                        }
                    } else if (typeof(responses[0].address_components[i]) === "object" && responses[0].address_components[i].types[0] == "postal_code") {
                        if (typeof responses[0].address_components[i].long_name != undefined){
                            $('#end_cep').val(responses[0].address_components[i].long_name.toUpperCase());
                        }
                    }
                }
            } else {
                marker.formatted_address = 'Não é possivel localizar o endereço.';
            }
            infowindow.setContent(marker.formatted_address + "<br>Coordenadas: " + marker.getPosition().toUrlValue(6));
            infowindow.open(map, marker);
        });

Thank you.

Emerson

    
asked by anonymous 05.09.2016 / 21:18

0 answers