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 地圖平台 API 提供的地圖中使用地理編碼資料。