Skip to content Skip to sidebar Skip to footer

Get Address And Zipcode With Longitude And Latitude In Google Map

in google map api, i want to extract map center latitude and longitude and get address of there like a zipcode. this is possible to get zipcode ? i use this for this purpose var la

Solution 1:

You can get postal code searching for postal_code type:

if (status == google.maps.GeocoderStatus.OK) {
        if (results[0]) {
            for (var i = 0; i < results[0].address_components.length; i++) {
                var types = results[0].address_components[i].types;

                for (var typeIdx = 0; typeIdx < types.length; typeIdx++) {
                    if (types[typeIdx] == 'postal_code') {
                        //console.log(results[0].address_components[i].long_name);console.log(results[0].address_components[i].short_name);
                    }
                }
            }
        } else {
            console.log("No results found");
        }
    }

Solution 2:

As far as I'm aware, you've answered your own question here. The 'Postal Code' is the generic name given to the mailing address identifier used in each country. In the case of the US this would be the 'Zip Code', in the UK the 'Post Code' etc.

From the documentation you linked:

postal_code indicates a postal code as used to address postal mail within the country.

The field under Postal Code is likely what you're looking for, don't let the naming convention fool you. It would be unnecessary work on the part of Google to rename the field for each country's possible variations.

Post a Comment for "Get Address And Zipcode With Longitude And Latitude In Google Map"