当我运行该代码时,我收到错误!
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)! )