Why some addresses do not have all components when using Google Maps Geolocation?

Viewed 104

I wrote this function to obtain address from coordinates using Google Maps API.

var geocoder = new google.maps.Geocoder();

function setMap(pos) {
    map.setCenter(pos);

    geocoder.geocode({ latLng: pos }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            $("#address").val(results[0].formatted_address + ", Coordinates: " + results[0].geometry.location.lat() + "," + results[0].geometry.location.lng());

            console.log("init  address", results[0]);
        }
        else {
            $("#address").val("Couldn't find your address, please use search feature.");
        }
    });
}

Then I'm trying to fetch individual address fields from address_components array:

        $.each(address.address_components, function(i, component) {
            $.each(component.types, function(j,type) {
                if (type === 'route') {
                    $("#street_name").val(component.long_name)
                }
                if (type === 'street_number') {
                     $("#street_number").val(component.long_name)
                }
            })
        })

The problem is that for some places formatted_address property conatins street number and street name but it does not contain those as individual fields in address_components.

Example below:

enter image description here

Is it that Google hasn't updated these?

0 Answers
Related