【问题标题】:Retrieving the place ID of a city with the Google Maps/Places SDK on iOS在 iOS 上使用 Google Maps/Places SDK 检索城市的地点 ID
【发布时间】:2023-03-20 15:28:01
【问题描述】:

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

我想要实现的是发送一个城市的名称/邮政编码/坐标或类似的东西,然后返回标识该城市的地点 ID。

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

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

【问题讨论】:

    标签: ios swift google-maps google-maps-api-3 google-places-api


    【解决方案1】:

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

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

    您将需要使用此类来使用自动完成功能获取位置...

    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

    【讨论】:

    • 这是我的第一个猜测,但是如何从坐标中获取 GMSPlace 对象?
    • LajosDeme 我更新了我的答案,为您提供使用坐标获取 GMSPlaces 的方法。这是一个指向我的仓库的链接,我在其中做了类似于你正在尝试做的事情(看看我的方法 setupPlacesClient() ) - github.com/victis23/Inventory-Tracker-Iphone-App/blob/…
    • 谢谢!你刚刚拯救了我的一天!
    猜你喜欢
    • 1970-01-01
    • 2013-04-14
    • 2013-02-11
    • 2015-08-01
    • 2012-05-14
    • 2013-10-06
    • 2013-09-09
    • 1970-01-01
    • 2018-03-03
    相关资源
    最近更新 更多