開始使用

Geocoding API 服務提供地址的地理編碼及反向地理編碼。

「地理編碼」是指將地址 (例如街道地址) 轉換成地理座標 (例如經緯度) 的過程,您可以使用這項程序在地圖上放置標記或設定地圖位置。

反向地理編碼是指將地理座標轉換為清楚易懂地址的程序。

您也可以使用 Geocoding API 找出特定地點 ID 的地址。

要求與回應範例

您可透過 HTTP 介面存取 Geocoding API。以下是地理編碼和反向地理編碼要求的示例。

地理編碼要求與回應 (經緯度查詢)

以下範例要求「1600 Amphitheatre Parkway, Mountain View, CA」的經緯度,並指定輸出採用 JSON 格式。

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY

如要進行測試,請在網路瀏覽器中輸入網址 (務必將 YOUR_API_KEY 替換成實際的 API 金鑰)。回應會包含地址的經緯度。

請參閱開發人員指南,進一步瞭解如何 建構地理編碼要求網址可用參數,以及 瞭解回應

以下是 JSON 格式的地理編碼回應範例:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "1600",
               "short_name" : "1600",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Amphitheatre Parkway",
               "short_name" : "Amphitheatre Pkwy",
               "types" : [ "route" ]
            },
            {
               "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" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "94043",
               "short_name" : "94043",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
         "geometry" : {
            "location" : {
               "lat" : 37.4267861,
               "lng" : -122.0806032
            },
            "location_type" : "ROOFTOP",
            "viewport" : {
               "northeast" : {
                  "lat" : 37.4281350802915,
                  "lng" : -122.0792542197085
               },
               "southwest" : {
                  "lat" : 37.4254371197085,
                  "lng" : -122.0819521802915
               }
            }
         },
         "place_id" : "ChIJtYuu0V25j4ARwu5e4wwRYgE",
         "plus_code" : {
            "compound_code" : "CWC8+R3 Mountain View, California, United States",
            "global_code" : "849VCWC8+R3"
         },
         "types" : [ "street_address" ]
      }
   ],
   "status" : "OK"
}

反向地理編碼要求與回應 (地址查詢)

以下範例會要求與美國紐約州布魯克林的指定經緯度對應的地址。它指定輸出內容必須是 JSON 格式。

https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY

您可以在網路瀏覽器中輸入網址來進行測試 (務必將「YOUR_API_KEY」替換成實際的 API 金鑰)。回應包含經緯度位置的清楚易懂地址。

請參閱開發人員指南,進一步瞭解如何 建構反向地理編碼要求網址可用參數,以及 瞭解回應

以下是 JSON 格式的反向地理編碼回應範例:

{
   "plus_code" : {
      "compound_code" : "P27Q+MC New York, NY, USA",
      "global_code" : "87G8P27Q+MC"
   },
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "279",
               "short_name" : "279",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Bedford Avenue",
               "short_name" : "Bedford Ave",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Williamsburg",
               "short_name" : "Williamsburg",
               "types" : [ "neighborhood", "political" ]
            },
            {
               "long_name" : "Brooklyn",
               "short_name" : "Brooklyn",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Kings County",
               "short_name" : "Kings 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" ]
            },
            {
               "long_name" : "11211",
               "short_name" : "11211",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "279 Bedford Ave, Brooklyn, NY 11211, USA",
         "geometry" : {
            "location" : {
               "lat" : 40.7142484,
               "lng" : -73.9614103
            },
            "location_type" : "ROOFTOP",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.71559738029149,
                  "lng" : -73.9600613197085
               },
               "southwest" : {
                  "lat" : 40.71289941970849,
                  "lng" : -73.96275928029151
               }
            }
         },
         "place_id" : "ChIJT2x8Q2BZwokRpBu2jUzX3dE",
         "plus_code" : {
            "compound_code" : "P27Q+MC Brooklyn, New York, United States",
            "global_code" : "87G8P27Q+MC"
         },
         "types" : [
            "bakery",
            "cafe",
            "establishment",
            "food",
            "point_of_interest",
            "store"
         ]
      },

   ... Additional results truncated in this example[] ...

   ],
   "status" : "OK"
}

開始使用我們的用戶端程式庫編寫程式碼

用戶端程式庫提供簡單的原生實作項目 (例如驗證、要求節流和自動重試),方便您利用 Google Maps 網路服務 API 進行開發。Geocoding API 適用於 Google 地圖服務適用的 Java 用戶端、Python 用戶端、Go 用戶端和 Node.js 用戶端

驗證、配額、定價和政策

驗證

如要使用 Geocoding API,您必須先啟用 API 並取得適當的驗證憑證。詳情請參閱「開始使用 Google 地圖平台」一文。

配額與定價

請參閱用量與計費頁面,進一步瞭解 Geocoding API 的配額與定價。

政策

使用 Geocoding API 時必須遵守 API 政策

瞭解詳情

Geocoding API 還有更多其他功能。如要查看其他示範內容、範例、可用參數、狀態碼和錯誤訊息,請參閱 Geocoding API 開發人員指南

如要瞭解 Geocoding API 網路服務,請參閱 Geocoding API 開發人員指南。這項計畫旨在協助網站和 Google 行動服務開發人員使用任一 Google 地圖平台 API 所提供地圖中的地理編碼資料。