使用 Places API 和地理编码服务来设置边界的数据驱动型样式
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您可以将 Places SDK for iOS 和 Geocoding API 与 Maps SDK for iOS 搭配使用,以搜索区域并获取有关地点的更多信息。Places SDK for iOS 和 Geocoding API 拥有强大且稳定的性能,二者都可用来获取地点 ID。如果您已经在使用地点 ID,就可以重复使用这些 ID 来设置边界的数据驱动型样式。
您可以通过以下方式将地点服务和地理编码服务添加到您的 Maps SDK for iOS 应用:
使用 Places API
获取某个区域的地点详情
区域的地点详情数据也有效。例如,您可以:
- 根据地点名称搜索边界地点 ID。
- 获取视口以缩放至相应边界。
- 获取边界的地图项类型(例如,位置)。
- 获取采用特定格式的地址。美国区域的地址会解析为“地点名称,州,国家”(例如“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
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):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 ```"]]