使用 Xcode 6.4 在 swift 中使用 GMSPlacesClient 时出错

Error when using GMSPlacesClient in swift using Xcode 6.4

我正在关注 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'

请提出建议..谢谢

您可以删除 placeLikelihoods 之后的“:GMSPlaceLikelihoodList”,它应该可以工作。对于我使用过的所有 GMSPlaceClient 方法,您不需要在回调中包含参数类型

swift3,xcode8.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)")
        }
    }
})

代码工作正常,但仍然显示错误,"The operation couldn’t be completed. An internal error occurred in the Places API library"。但至少,它是可以建造的。