【发布时间】:2016-04-14 11:14:20
【问题描述】:
placesClient 给出了持有 nil 值的错误,在阅读了 google places 文档后,我阅读了以下声明:
应通过 [GMSPlacesClient sharedClient] 方法访问此类。
我想知道如何实现 sharedClient 方法,以便根据placesID 运行搜索以获取给定地点的信息?
var placesClient: GMSPlacesClient!
func lookUpPlaceID() {
let placeID = "ChIJPXw5JDZM6IAR4rTXaFQDGys"
//What value should placesClient be holding if not GMSPlacesClient in order to run the search based on the placeID?
self.placesClient.lookUpPlaceID(placeID, callback: { (place, error) -> Void in
if let error = error {
print("lookup place id query error: \(error.localizedDescription)")
return
}
if let place = place {
print("Place name \(place.name)")
print("Place address \(place.formattedAddress)")
print("Place placeID \(place.placeID)")
print("Place attributions \(place.attributions)")
} else {
print("No place details for \(placeID)")
}
})
}
【问题讨论】:
-
哎呀。将代码更新为我实际拥有的代码。什么可能是不正确的?谢谢
-
placesClient(声明为隐式展开的可选)为 nil,而不是placeID。 -
哇,这很有趣。但是现在我肯定不知道应该做什么才能通过 google places api 获取信息。 :(
-
我的第一个真正的应用程序进程。但仍然没有真正得到应该为 placesClient 分配什么值?
标签: swift callback google-places-api google-maps-sdk-ios