获得给定邮政编码和/或地址字符串的纬度和经度

时间:2014-10-08 14:24:33

标签: google-maps google-api google-places-api

这种旧的API语法:

https://maps.googleapis.com/maps/api/geocode/json?address=L12+3TS%2c%2bUK&sensor=false&client=XYZ&signature=XYZ

应返回给定英国邮政编码的纬度和经度。它返回:

{
  "Status": {
    "code": 620,
    "request": "geocode",
    "error_message": "The Geocoding API v2 has been turned down on September 9th, 2013. The Geocoding API v3 should be used now. Learn more at https://developers.google.com/maps/documentation/geocoding/"
  }
}

这是公平的。我研究过this但是找不到新的语法。有人可以帮帮我吗?理想情况下,我还希望能够获得给定英国地址字符串的纬度和经度。感谢。

1 个答案:

答案 0 :(得分:0)

https://maps.googleapis.com/maps/api/geocode/json?address=L12+3TS%2c%2bUK&sensor=false

正在为我工​​作(我删除了客户端和签名信息),给出了以下结果:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "L12",
               "short_name" : "L12",
               "types" : [ "postal_code_prefix", "postal_code" ]
            },
            {
               "long_name" : "Liverpool",
               "short_name" : "Liverpool",
               "types" : [ "postal_town" ]
            },
            {
               "long_name" : "Merseyside",
               "short_name" : "Mersyd",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Royaume-Uni",
               "short_name" : "GB",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Liverpool, Merseyside L12, Royaume-Uni",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 53.4605852,
                  "lng" : -2.8675854
               },
               "southwest" : {
                  "lat" : 53.4183146,
                  "lng" : -2.9233403
               }
            },
            "location" : {
               "lat" : 53.43679479999999,
               "lng" : -2.8881009
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 53.4605852,
                  "lng" : -2.8675854
               },
               "southwest" : {
                  "lat" : 53.4183146,
                  "lng" : -2.9233403
               }
            }
         },
         "partial_match" : true,
         "types" : [ "postal_code_prefix", "postal_code" ]
      }
   ],
   "status" : "OK"
}

所以问题可能出在你的客户参数上。