如何使用 Google Places API 获取邮政编码?

How to get postal code with using Google Places API?

我使用 Google 个地方 API 来实现自动完成。

我注意到 Google 地点 API 没有 return 某些地址的邮政编码:

URL: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=3&types=address&language=en&key=MY_KEY

预测之一:

description = "3rd Avenue, NY, United States";
id = b9ea1b2047021e7b8f4d1e2d2033b4baafcc8d21;
"matched_substrings" =     (
            {
        length = 1;
        offset = 0;
    }
);
"place_id" = Eh0zcmQgQXZlbnVlLCBOWSwgVW5pdGVkIFN0YXRlcw;
reference = "CjQhAAAAZddDjaWNLgFtHPG-JqwGI9W4kfxDj0DwYLQ9WtzJ8BdKJ-q7qu0YcrGHfdYCs_6-EhB6ZULyxVK-yFVOMmjt17XIGhT76Ln6Cy1sukn0DMKMLiqMADMmbg";
terms =     (
            {
        offset = 0;
        value = "3rd Avenue";
    },
            {
        offset = 12;
        value = NY;
    },
            {
        offset = 16;
        value = "United States";
    }
);
types =     (
    route,
    geocode
);

而且,连return邮编都没有,我打电话详细说这个地方的时候

URL: https://maps.googleapis.com/maps/api/place/details/json?reference=CjQhAAAAtTsm_rHPRkKVkTBCXhFiRX7hjWshEAchbcqQslgpJaZEaDWyzqGzWsMmaZItCGO7EhCzWXberoKVpm0eIMJd8Uk2GhQxEpgyR_XiYLsvU3tc43ZsrK_M2Q&language=en&key=MY_KEY

结果:

"html_attributions" =     (
);
result =     {
    "address_components" =         (
                    {
            "long_name" = "3rd Ave";
            "short_name" = "3rd Ave";
            types =                 (
                route
            );
        },
                    {
            "long_name" = Manhattan;
            "short_name" = Manhattan;
            types =                 (
                "sublocality_level_1",
                sublocality,
                political
            );
        },
                    {
            "long_name" = "New York";
            "short_name" = NY;
            types =                 (
                locality,
                political
            );
        },
                    {
            "long_name" = "New York County";
            "short_name" = "New York County";
            types =                 (
                "administrative_area_level_2",
                political
            );
        },
                    {
            "long_name" = "New York";
            "short_name" = NY;
            types =                 (
                "administrative_area_level_1",
                political
            );
        },
                    {
            "long_name" = "United States";
            "short_name" = US;
            types =                 (
                country,
                political
            );
        }
    );
    "adr_address" = "<span class=\"street-address\">3rd Ave</span>, <span class=\"locality\">New York</span>, <span class=\"region\">NY</span>, <span class=\"country-name\">USA</span>";
    "formatted_address" = "3rd Ave, New York, NY, USA";
    geometry =         {
        location =             {
            lat = "40.769058";
            lng = "-73.9611034";
        };
    };
    icon = "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png";
    id = b9ea1b2047021e7b8f4d1e2d2033b4baafcc8d21;
    name = "3rd Ave";
    "place_id" = ChIJAScMMupYwokRnhWalEuqcnc;
    reference = "CoQBfQAAACR4npz_DDE5pbhlslJYJ6h4obSF9CIvnIvEfySMR_FNLUFCfGGYOM858hmM8_FibAaO0AlA0Qq7EhFqorMoTh6jzknlsXRmwX2sMVSgqGX6YgGmzPPvlqHTOdAuXbWMYuKACZXiiJN4F4xpWmWgwqIXPRKU6qg0f8e3b-N9q5vQEhBHvnjfb7TBlz18IhaVnX1yGhTwAeuiDacEGbUVezjTvMQhXzK1Kw";
    scope = GOOGLE;
    types =         (
        route
    );
    url = "https://maps.google.com/maps/place?q=3rd+Ave,+New+York,+NY,+USA&ftid=0x89c258ea320c2701:0x7772aa4b949a159e";
    vicinity = Manhattan;
};
status = OK;

如何使用 Google 地点 API 获取邮政编码?

这些结果可能太大,以至于没有一个唯一的邮政编码。如果您对返回的位置进行反向地理编码(不会是 "using the Google Places API"),它将(可能)有一个邮政编码(至少返回的最精确的结果会有),但这是否有用还有待观察。