【问题标题】:CLGeocoder Swift 2 VersionCLGeocoder Swift 2 版本
【发布时间】:2015-07-11 19:19:44
【问题描述】:

这曾经在 Swift 1.2 中运行良好,但现在出现错误:

“不能使用类型为'(String, completionHandler: ([AnyObject]!, NSError!) -> Void)'的参数列表调用'geocodeAddressString'”

geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [AnyObject]!, error: NSError!) -> Void in
            if let placemark = placemarks?[0] as? CLPlacemark {
                let annotation = MKPointAnnotation()

编辑答案:

geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [CLPlacemark]?, error: NSError?) -> Void in

【问题讨论】:

    标签: ios geocode swift2


    【解决方案1】:

    完成处理程序中的变量设置不正确,您没有包含声明,所以只是 -

    coder.geocodeAddressString("1 infinite loop, cupertino, ca") { (placemarks, error) -> Void in
    
        if let firstPlacemark = placemarks?[0] {
            print(firstPlacemark)
        }   
    }
    

    请注意,类型推断所知道的不需要的可选转换将是 CLPlacemark

    【讨论】:

      猜你喜欢
      • 2016-01-11
      • 2021-11-28
      • 1970-01-01
      • 2017-02-26
      • 1970-01-01
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      • 2019-03-31
      相关资源
      最近更新 更多