0

How get post code? I try use it:

google.maps.event.addListener(autocomplete, 'place_changed', function() {
        var place = autocomplete.getPlace();
        //get postal code
        for (var i = 0; i < place.address_components.length; i++) {
            for (var j = 0; j < place.address_components[i].types.length; j++) {
                if (place.address_components[i].types[j] == "postal_code") {
                    console.log(place.address_components[i].long_name);

                }
            }
        }

..}

But it doen't work for almost all addresses ( sometime it works , with several addresses). For example, for "Sumska Street, Kharkiv, Kharkiv Oblast, Ukraine" it doesn't work. Maybe there is another way to get post code? Hpw can I solve this problem? Thanks!

Nastya Nastya
  • 95
  • 3
  • 10
  • 1
    Google Maps doesn't have a postal code for that address. https://www.google.com/maps/place/Sumska+St,+Kharkiv,+Kharkiv+Oblast,+Ukraine – SLaks May 21 '17 at 19:05
  • Possible duplicate of [Retrieving Postal Code with Google Maps Javascript API V3 Reverse Geocode](http://stackoverflow.com/questions/5341023/retrieving-postal-code-with-google-maps-javascript-api-v3-reverse-geocode) – Siphalor May 21 '17 at 19:17
  • That street doesn't have a post_code (probably spans several). You need to request a location that is more specific. It looks to me like all the locations around the lat/lng coordinates returned by that autocomplete result (which is an intersection), have a post_code of 61000 – geocodezip May 21 '17 at 20:29
  • It looks like Google has only one postal code for the entire city of Kharkiv 61000. https://www.google.com/maps/place/Kharkiv,+Kharkiv+Oblast,+Ukraine,+61000/@50.0020572,36.2388348,11.48z/data=!4m5!3m4!1s0x4127a0993d55c183:0xd8cd77146ba2b328!8m2!3d49.9935!4d36.230383 The postal code coverage seems to be poor in Ukraine. – xomena May 23 '17 at 13:51
  • Probably the reliable way is to execute reverse geocode for coordinates of this street. Something like https://maps.googleapis.com/maps/api/geocode/json?latlng=50.0106394%2C36.2411565&result_type=postal_code&key=YOUE_API_KEY. You can also do reverse geocode in JavaScript API. – xomena May 23 '17 at 14:00

0 Answers0