1
I did a dragger on google maps, which moving the Marketer to the street, it returns all the data from the street/av/lane etc.
My question is this: :
- It has some address that returns 5 digits, this is normal ?
- How you usually treat the address with 5-digit zip code ?]
Example : Searching for this address : Avenida Alexandre Mackenzie
He returns me this cep : 05322
What I do wrong in my 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
The JS code that is returning the zip code would be welcome. However, without further analysis, I think you could simply add 000 when you return 5 digits.
– Reginaldo Rigo
js code is this :
– paladin
This happened to me in strains that end with "000". I just check if returned only 5 number and complete with 000, but if you test the strains they are not wrong.
– André Vicente