我遵循Google API文档并尝试查找当前设备周围的位置。我正在尝试使用GMSPlacesClient.currentPlaceWithCallback。
文档示例是
GMSPlacesClient.currentPlaceWithCallback({ (placeLikelihoods: GMSPlaceLikelihoodList,error) -> Void in
if error != nil {
println("Current Place error: \(error.localizedDescription)")
return
}
for likelihood in placeLikelihoods.likelihoods {
if let likelihood = likelihood as? GMSPlaceLikelihood {
let place = likelihood.place
println("Current Place name \(place.name) at likelihood \(likelihood.likelihood)")
println("Current Place address \(place.formattedAddress)")
println("Current Place attributions \(place.attributions)")
println("Current PlaceID \(place.placeID)")
}
}
})
然而,它失败了构建错误无法使用类型'((GMSPlaceLikelihoodList,_) - > Void)'的参数列表调用'currentPlaceWithCallback'
建议请...谢谢
答案 0 :(得分:0)
您可以在placeLikelihoods之后删除“:GMSPlaceLikelihoodList”,它应该可以正常工作。对于我使用的所有GMSPlaceClient方法,您不需要在回调中包含参数类型
答案 1 :(得分:0)
swift 3,xcode 8.1
这是我的代码段,在通过CocoaPods添加GooglePlaces
之后,请确保您已声明let var placesClient: GMSPlacesClient?
并获得CLLocationManager
的授权
placesClient?.currentPlace(callback: { (placeLikelihoodList, error) in
if error != nil {
print("Current Place error: \(error!.localizedDescription)")
return
}
if let placeLicklihoodList = placeLikelihoodList {
let place = placeLicklihoodList.likelihoods.first?.place
if let place = place
{
print("Current Place address \(place.formattedAddress)")
print("Current Place attributions \(place.attributions)")
print("Current PlaceID \(place.placeID)")
}
}
})
代码工作正常,但仍然显示错误,“操作无法完成.Parks API库中发生内部错误”。但至少,它可以建立。