我想根据邮政编码和国家/地区代码查找城市,州信息

时间:2019-06-14 21:41:15

标签: google-api

我想根据两个输入(即邮政编码和国家/地区)找出县,城市,州,phoneAreaCode,纬度,经度,cityStateKey

我尝试浏览google api文档,但是他们的文档非常繁琐。

输入- “ CountryCode”:“美国”, “ postalCode”:“ 60090”

输出- “ provinceCode”:“ IL”, “ county”:“ COOK”, “ phoneAreaCode”:“ 847/312/224/630/708”, “纬度”:42.124293, “经度”:-87.924184, “ cityStateKey”:“ W15521”, “ cityName”:“呼啸”

1 个答案:

答案 0 :(得分:1)

研究期间发现,Google的Places API中的“查找位置请求”最适合此要求。

以下是请求和响应:

请求:

https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=06850&inputtype=textquery&fields=formatted_address,name,geometry,types&key=API_KEY

响应:

{
    "candidates": [
        {
            "formatted_address": "New York, NY 10029, USA",
            "geometry": {
                "location": {
                    "lat": 40.79164069999999,
                    "lng": -73.94479939999999
                },
                "viewport": {
                    "northeast": {
                        "lat": 40.79299052989272,
                        "lng": -73.94344957010728
                    },
                    "southwest": {
                        "lat": 40.79029087010727,
                        "lng": -73.94614922989271
                    }
                }
            },
            "name": "New York, NY 10029",
            "types": [
                "postal_code"
            ]
        }
    ],
    "status": "OK"
}