CLGeocodeCompletionHandler ios swift3

Ste*_*Lam 0 clgeocoder swift3

有没有人知道swift3上的任何变化?如何修复以下代码我使用geococdeAddressString

class func getMapByAddress(_ locationMap:MKMapView?, address:String?, title: String?, subtitle: String?)
{
            let geocoder = CLGeocoder()
            geocoder.geocodeAddressString(address!, completionHandler: {(placemarks: [CLPlacemark]?, error: NSError?) -> Void in
                if let validPlacemark = placemarks?[0]{
                    print(validPlacemark.location?.coordinate)

                    let span = MKCoordinateSpanMake(0.05, 0.05)
                    let region = MKCoordinateRegion(center: (validPlacemark.location?.coordinate)!, span: span)
                    locationMap?.setRegion(region, animated: true)

                    let annotation = MKPointAnnotation()
                    annotation.coordinate = (validPlacemark.location?.coordinate)!
                    annotation.title = title
                    annotation.subtitle = subtitle
                    locationMap?.addAnnotation(annotation)
                }

            } as! CLGeocodeCompletionHandler)
}
Run Code Online (Sandbox Code Playgroud)

这一行出错......只是在此行崩溃,as! CLGeocodeCompletionHandler) 没有显示错误<private>

Mah*_*a Y 10

使用以下代码即删除[CLPlacemark]?和NSError?从完成处理程序

class func getMapByAddress(_ locationMap:MKMapView?, address:String?, title: String?, subtitle: String?)
    {
        let geocoder = CLGeocoder()
        geocoder.geocodeAddressString(address!, completionHandler: {(placemarks, error) -> Void in
            if let validPlacemark = placemarks?[0]{
                print(validPlacemark.location?.coordinate)

                let span = MKCoordinateSpanMake(0.05, 0.05)
                let region = MKCoordinateRegion(center: (validPlacemark.location?.coordinate)!, span: span)
                locationMap?.setRegion(region, animated: true)

                let annotation = MKPointAnnotation()
                annotation.coordinate = (validPlacemark.location?.coordinate)!
                annotation.title = title
                annotation.subtitle = subtitle
                locationMap?.addAnnotation(annotation)
            }

            })
    }
Run Code Online (Sandbox Code Playgroud)