Google Maps Geo geocode 610問題

摘要:Google Maps Geo geocode 610問題

 

 

原由:

今天又遇到一個問題,原因是維護舊有的程式,舊有的程式有呼叫google restful api 取得地理位置坐標,

但是用的是v2的版本,導致,程式回傳610,如下連結,然後找到原因是,v2版本已廢止,剛好是在今年3/8之後,

http://maps.google.com/maps/geo?q=台北市&h1=zh-TW&output=json

第二版,版本操作解說:

https://developers.google.com/maps/documentation/geocoding/v2/?hl=zh-tw#JSON

新版本,操作解說:

https://developers.google.com/maps/documentation/geocoding/?hl=zh-tw

回傳格式如下

 

{
  "Status": {
    "code": 610,
    "request": "geocode"
  }
}

問題原因:

Note: Version 2 ("v2") of the Geocoding API was officially deprecated on 8 March 2010 and was only guaranteed to work until 8 March 2013. The official deprecation date has been extended until 8 September 2013, after which time the API will cease to work. We encourage you to migrate your code to the new Geocoding API. Please refer to the upgrade guide for information on how to migrate to the v3 API.

注:第2版(“V2”)於2010年3月8日被正式棄用的地理編碼API,只保證工作,直到2013年3月8日。正式棄用日期已延長至2013年9月後的API將停止工作。我們鼓勵您代碼遷移到新的地理編碼API。有關如何遷移到V3 API的信息,請參閱升級指南。

解決辦法:

http://maps.google.com/maps/geo?q=台北市&h1=zh-TW&output=json

改為

http://maps.googleapis.com/maps/api/geocode/json?address=台北市&language=zh-TW&sensor=false

 

產出的格式會變成如下:





{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "台北市",
               "short_name" : "北市",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "台灣",
               "short_name" : "TW",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "台灣台北市",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 25.21030380,
                  "lng" : 121.66594210
               },
               "southwest" : {
                  "lat" : 24.96050840,
                  "lng" : 121.45706030
               }
            },
            "location" : {
               "lat" : 25.0910750,
               "lng" : 121.55983450
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 25.21030380,
                  "lng" : 121.66594210
               },
               "southwest" : {
                  "lat" : 24.96050840,
                  "lng" : 121.45706030
               }
            }
         },
         "postcode_localities" : [],
         "types" : [ "administrative_area_level_2", "political" ]
      }
   ],
   "status" : "OK"
}

 

 

 

 

 

 

使用限制:

Google Geocoding API 有查詢限制,每天只能發出 2,500 個地理位置要求 (Google Maps API for Business 使用者每天最多可執行 100,000 個要求)。要實施這項限制的原因,是避免有人濫用 Geocoding API 以及/或將其用在其他目的。此限制日後如有變更,恕不另行通知。此外,我們也限制要求頻率,以避免發生濫用服務的狀況。如果您已超過 24 小時的使用上限或是濫用服務,Geocoding API 將暫時無法運作。如果您持續超過上限,則會遭到封鎖,無法使用 Geocoding API。

 

參考語言表

https://spreadsheets.google.com/a/jamzoo.com.tw/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1

 

格式與參數說明參考

https://developers.google.com/maps/documentation/geocoding/index?hl=zh-tw

 

必要參數為:

 

  • address:您要進行地理編碼的地址。 
          
    latlng:您將為此文字經/緯度值取得最接近的人類可讀地址。詳情請見反向地理編碼。 
          
    components:您想為其取得地理編碼的元件篩選器。詳請請見元件篩選。如果您提供了 address,系統也可以接受元件篩選器做為選用參數。
  • sensor:指出地理編碼要求的來源裝置是否附有位置感應器。這個值必須是 true 或 false

 

輸出參數可為json或xml