【问题标题】:Error when using GMSPlacesClient in swift using Xcode 6.4使用 Xcode 6.4 快速使用 GMSPlacesClient 时出错
【发布时间】:2015-08-19 17:14:13
【问题描述】:

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

请提出建议..谢谢

【问题讨论】:

    标签: ios xcode swift google-maps-sdk-ios


    【解决方案1】:

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

    【讨论】:

    • 尽管我删除了“:GMSPlaceLikelihoodList”,但仍然返回错误。请提出其他建议。这不起作用
    【解决方案2】:

    swift 3,xcode 8.1

    这是我的代码 sn-ps,在通过 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)")
            }
        }
    })
    

    代码运行良好,但仍显示错误“无法完成操作。Places API 库中发生内部错误”。但至少,它是可以建造的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-24
      • 1970-01-01
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-17
      相关资源
      最近更新 更多