使用 Places API 和 Geocoding API 搭配界線資料導向樣式
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
您可以在 Maps SDK for iOS 中使用 Places SDK for iOS 和 Geocoding API 搜尋區域,並取得地點的詳細資訊。Places SDK for iOS 和 Geocoding API 是功能強大且穩定的替代方案,可用於取得地點 ID。如果您使用地點 ID,就能透過界線資料導向樣式重複使用這些 ID。
在 Maps SDK for iOS 應用程式中加入 Places API 和 Geocoding API 的方法如下:
使用 Places API
取得區域的地點詳細資料
區域的地點詳細資料也十分實用。例如,您可以:
- 根據地點名稱搜尋界線地點 ID。
- 取得可視區域以縮放至界線。
- 取得界線的地圖項目類型 (例如 locality)。
- 取得格式化地址,在美國區域中,這個地址會解析為「地點名稱, 州, 國家」,例如「Kirkland, WA, USA」。
- 取得相片等其他實用資料。
使用 Geocoding API
您可以使用 Geocoding API 將地址、經緯度座標或地點 ID 轉換為地理座標,反之亦然。以下應用實例適合搭配界線資料導向樣式:
- 透過地理編碼取得區域的可視區域。
- 針對地理編碼呼叫進行元件篩選,取得行政區 1 到 4、縣市或郵遞區號的地點 ID。
- 透過反向地理編碼,按經緯度座標尋找地點 ID,甚至是針對特定位置的所有元件傳回地點 ID。
下列範例使用地址 (經過網址逸出處理) 向 Geocoding API 提出要求:
https://maps.googleapis.com/maps/api/geocode/json?latlng=41.864182,-87.676930&key=YOUR_API_KEY
您可以使用反向地理編碼找出地點 ID。以下地理編碼服務函式範例會傳回指定經緯度座標上所有地址元件的地點 ID:
https://maps.googleapis.com/maps/api/geocode/json?latlng=41.864182,-87.676930&result_type=locality&key=YOUR_API_KEY
搭配元件篩選使用反向地理編碼,即可取得指定位置上一或多種下列類型的地址元件:
administrativeArea
country
locality
postalCode
schoolDistrict
以下範例說明如何使用地理編碼服務,透過反向地理編碼加入元件限制,擷取指定位置上的所有地址元件 (僅限 locality
類型):
https://maps.googleapis.com/maps/api/geocode/json?latlng=41.864182,-87.676930&result_type=locality&key=YOUR_API_KEY
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eYou can search for and get information about regions using the Places SDK for iOS and the Geocoding API with the Maps SDK for iOS.\u003c/p\u003e\n"],["\u003cp\u003eThe Places API Text Search and Autocomplete service enable searching for regions based on text strings and user input.\u003c/p\u003e\n"],["\u003cp\u003ePlace Details provide comprehensive information about regions, including boundary place IDs, viewport for zooming, and feature type.\u003c/p\u003e\n"],["\u003cp\u003eThe Geocoding API facilitates converting addresses and coordinates into geographic coordinates and vice-versa, useful for retrieving viewport, place IDs, and address components.\u003c/p\u003e\n"],["\u003cp\u003eReverse geocoding with the Geocoding API allows finding place IDs based on latitude and longitude coordinates and applying component filtering for specific address types.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/maps/documentation/android-sdk/dds-boundaries/dds-use-maps-places-apis \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/dds-boundaries/dds-use-maps-places-apis \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/dds-boundaries/dds-use-maps-places-apis \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\n**European Economic Area (EEA) developers** If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](/maps/comms/eea/faq).\n\nYou can use the Places SDK for iOS and the\nGeocoding API with the Maps SDK for iOS to\nsearch for regions, and get more information about places. The\nPlaces SDK for iOS and Geocoding API\nare powerful and stable alternatives for obtaining [place\nIDs](/maps/documentation/places/ios-sdk/place-id). If you're already using place\nIDs, you can reuse those IDs with data-driven styling for boundaries.\n\nAdd Places and Geocoding to your Maps SDK for iOS apps in the following ways:\n\n- [Places SDK for iOS](/maps/documentation/places/ios-sdk) returns information about places using HTTP requests.\n- [CLGeocoder](https://developer.apple.com/documentation/corelocation/clgeocoder) class can geocode and reverse geocode dynamically from user input.\n- [Geocoding API](/maps/documentation/geocoding) lets you geocode static, known addresses.\n\n| **Note:** The [Places SDK for iOS](/maps/documentation/places/ios-sdk) and Geocoding API must be enabled, and are billed separately from the Maps SDK for iOS.\n\nUse the Places API\n\n- The [Places API Text\n Search](/maps/documentation/places/web-service/text-search) returns\n information about a set of places based on a string --- for example \"pizza in\n New York\" or \"shoe stores near Ottawa\" or \"123 Main Street\". The service\n responds with a list of places matching the text string and any location\n bias that has been set.\n\n- The [Places Autocomplete](/maps/documentation/places/ios-sdk/autocomplete#restrict_results_to_a_specific_region) service provides a convenient\n way to let your users search for regions. To display results within the\n defined region, set `locationRestriction` on\n [`GMSAutocompleteFilter`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSAutocompleteFilter).\n\nGet place details for a region\n\n- The [Place Details](/maps/documentation/places/ios-sdk/place-details) data\n for a region is also effective. For example, you can:\n\n - Search for boundary place IDs based on place names.\n - Get the viewport for zooming to a boundary.\n - Get the feature type for the boundary (for example locality).\n - Get the formatted address, which resolves to \"Place Name, State, Country\" in the United States region (for example, \"Kirkland, WA, USA\").\n - Get other useful data such as photos.\n\nUse the Geocoding API\n\n- The [Geocoding API](/maps/documentation/geocoding) lets you\n convert an address, latitude and longitude coordinates, or place ID into\n geographic coordinates, and vice-versa. The following uses combine well with\n data-driven styling for boundaries:\n\n - Use Geocoding to get the viewport for a region.\n - Apply component filtering to your Geocoding call to get the place IDs for administrative areas 1-4, locality, or postal code.\n - Use reverse geocoding to find place IDs by latitude and longitude coordinates, or even return place IDs for all components in a particular location.\n\n The following example uses an address (url-escaped) to make a request to the\n Geocoding API: \n\n ```html\n https://maps.googleapis.com/maps/api/geocode/json?latlng=41.864182,-87.676930&key=YOUR_API_KEY\n ```\n\n You can use [reverse\n geocoding](/maps/documentation/geocoding/requests-reverse-geocoding) to\n find place IDs. The following example Geocoding service function returns the\n place IDs for all address components at the specified latitude and longitude\n coordinates: \n\n ```html\n https://maps.googleapis.com/maps/api/geocode/json?latlng=41.864182,-87.676930&result_type=locality&key=YOUR_API_KEY\n ```\n\n Use reverse geocoding with component filtering to get the address component\n for one or more of the following types at the specified location:\n - `administrativeArea`\n - `country`\n - `locality`\n - `postalCode`\n - `schoolDistrict`\n\n The following example shows using the Geocoding service, adding component\n restrictions with reverse geocoding to retrieve all address components\n at the specified location for the `locality` type: \n\n ```html\n https://maps.googleapis.com/maps/api/geocode/json?latlng=41.864182,-87.676930&result_type=locality&key=YOUR_API_KEY\n ```"]]