地理编码错误:错误域= GEOErrorDomain代码= -8“(null)”

时间:2017-07-11 11:18:34

标签: ios swift xcode

当我运行该代码时,我收到错误!

 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let userLocation:CLLocation = locations[0] as CLLocation

    let userLoc = CLLocation(latitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude )

    for i in 0 ..< streetArray.count{

        let geoCoder = CLGeocoder()
        geoCoder.geocodeAddressString(self.streetArray[i]) { (placemarks, error) in

            let location = placemarks?.first?.location

            let destLoc = CLLocation(latitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)! )

            let distanceInMeters = userLoc.distance(from: destLoc)

            self.distanceArray.append(distanceInMeters)

            print(self.distanceArray)

        }

    }

    locationManager.stopUpdatingLocation()

}

为什么我收到错误的任何想法?

错误显示为线程1:EXC_Breakpoint ..

出现错误的行是

 let destLoc = CLLocation(latitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)! )

0 个答案:

没有答案