【问题标题】:Using an API to get the Location based on ZIP Code [closed]使用 API 根据邮政编码获取位置 [关闭]
【发布时间】:2014-11-10 08:12:00
【问题描述】:

在我的 Android 应用中,我想使用“国家/地区”和“邮政编码”来获取“州名”和“城市”或“村名”。

是否有任何 API 可用于获取此信息?

【问题讨论】:

标签: android google-api location


【解决方案1】:

对于印度,您可以使用以下 API

http://postalpincode.in/api/pincode/<your_pin_code>

回应:

{
  "Message": "Number of Post office(s) found: 2",
  "Status": "Success",
  "PostOffice": [
    {
      "Name": "ISRO Anthariksha Bhavan",
      "Description": "",
      "BranchType": "Sub Post Office",
      "DeliveryStatus": "Non-Delivery",
      "Taluk": "Bangalore North",
      "Circle": "Bangalore North",
      "District": "Bangalore",
      "Division": "Bangalore East",
      "Region": "Bangalore HQ",
      "State": "Karnataka",
      "Country": "India"
    },
    {
      "Name": "R.M.V. Extension II Stage",
      "Description": "",
      "BranchType": "Sub Post Office",
      "DeliveryStatus": "Delivery",
      "Taluk": "Bangalore North",
      "Circle": "Bangalore North",
      "District": "Bangalore",
      "Division": "Bangalore East",
      "Region": "Bangalore HQ",
      "State": "Karnataka",
      "Country": "India"
    }
  ]
}

对于国际邮政密码位置,请使用此

https://api.worldpostallocations.com/pincode?postalcode=<your_pin_code_eg: 560094>&countrycode=<two_digit_country_code_eg:IN>

回应

{
  "status": true,
  "result": [
    {
      "id": "305160",
      "country": "IN",
      "postalCode": "560094",
      "postalLocation": "ISRO Anthariksha Bhavan",
      "state": "Karnataka",
      "stateId": "19",
      "district": "Bengaluru",
      "districtId": "583",
      "province": "Bangalore North",
      "provinceId": "",
      "latitude": "13.1077",
      "longitude": "77.581"
    },
    {
      "id": "305159",
      "country": "IN",
      "postalCode": "560094",
      "postalLocation": "R.M.V. Extension II Stage",
      "state": "Karnataka",
      "stateId": "19",
      "district": "Bengaluru",
      "districtId": "583",
      "province": "Bangalore North",
      "provinceId": "",
      "latitude": "13.1077",
      "longitude": "77.581"
    }
  ]
}

【讨论】:

【解决方案2】:

您可以使用Google Geocoding API,带有 JSON 响应的简单 HTTP 请求。

示例:http://maps.googleapis.com/maps/api/geocode/json?address=94085&region=us

{
    long_name: "California",
    short_name: "CA",
    types: [
        "administrative_area_level_1",
        "political"
    ]
}

但请注意,免费层仅支持:

  • 每 24 小时有 2,500 个请求。
  • 每秒 5 个请求。

【讨论】:

    【解决方案3】:

    如果您使用 Google 地理编码器,您可以通过解析返回的 json 或 xml 并引用适当的字段来获取州和城市。例如:

    https://maps.googleapis.com/maps/api/geocode/json?address=94040
    

    返回

    {
       "results" : [
          {
             "address_components" : [
                {
                   "long_name" : "94040",
                   "short_name" : "94040",
                   "types" : [ "postal_code" ]
                },
                {
                   "long_name" : "Mountain View",
                   "short_name" : "Mountain View",
                   "types" : [ "locality", "political" ]
                },
                {
                   "long_name" : "Santa Clara County",
                   "short_name" : "Santa Clara County",
                   "types" : [ "administrative_area_level_2", "political" ]
                },
                {
                   "long_name" : "California",
                   "short_name" : "CA",
                   "types" : [ "administrative_area_level_1", "political" ]
                },
                ...
    

    【讨论】:

    • 出现错误:您必须使用 API 密钥来验证对 Google Maps Platform API 的每个请求。更多信息请参考g.co/dev/maps-no-account
    • 它要求 API 密钥
    【解决方案4】:

    可能有帮助

    https://www.whizapi.com/open-api/api-details?id=20

    网址-> https://www.WhizAPI.com/api/v2/util/ui/in/indian-city-by-postal-code?AppKey=your-app-key&pin=110001

    回应:

    {
    "ResponseCode": 0,
    "ResponseMessage": "OK",
    "ResponseDateTime": "11/10/2014 8:17:20 AM GMT",
    "Data": [
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Baroda House"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Bengali Market"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Bhagat Singh Market"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Connaught Place"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Constitution House"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Election Commission"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Janpath"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Krishi Bhawan"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Lady Harding Medical College"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "New Delhi",
            "Address": "New Delhi G.P.O."
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "North Avenue"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Parliament House"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Patiala House"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Pragati Maidan Camp"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Pragati Maidan"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Rail Bhawan"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Sansad Marg"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Sansadiya Soudh"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Secretariat North"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Shastri Bhawan"
        },
        {
            "Pincode": "110001",
            "Country": "INDIA",
            "City": "Central Delhi",
            "Address": "Supreme Court"
        }
    ]
    }
    

    【讨论】:

    • 如果有,请提供任何用于测试目的的 api 密钥,否则此 api 是否可以使用任何密码?
    • 无法打开网站
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-08
    • 2012-04-03
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    • 2011-10-31
    相关资源
    最近更新 更多