在 iOS 上使用 Google Maps/Places SDK 检索城市的地点 ID

Retrieving the place ID of a city with the Google Maps/Places SDK on iOS

我必须使用 Google 地图和 Google Places SDK-s 获取城市的地点 ID。我知道 GMSPlacesClient 包含使用地点 ID 访问地点 的方法,但反之则不然。

我想要实现的是发送一个城市的 name/zip 代码/坐标或类似的东西,并作为结果返回标识该城市的地点 ID。

我一直在研究 GMSPlacesClient at this link 的文档并试验这些方法几个小时,但我似乎无法实现这一点,无论这种能力多么基本。

如果您需要我提供更多相关信息,请告诉我。

您应该能够通过访问 GMSPlace 上的 .placeID 属性 来获取 placeID。

https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_place

您将需要使用此 class 通过自动完成获取位置...

https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_autocomplete_prediction

您将需要使用 GMSAutocompleteFilter()

的实例过滤您的搜索结果
let filter = GMSAutocompleteFilter()
filter.type = .city

https://developers.google.com/places/ios-sdk/reference/group___places_autocomplete_type_filter#gac7ff529f1296d874a5432707bce58671