我收到以下错误:
***由于未捕获的异常终止应用' NSInvalidArgumentException',原因:'无效区域< center:+37.32462723,-122.02352434 span:+0.00000260,-0.00055282>&#39 ;
这是我的代码:
class DetailViewController: UIViewController, MKMapViewDelegate {
var mapOverlay: MKTileOverlay!
let databaseRef = FIRDatabase.database().reference()
var databaseHandle: UInt!
var runName: String!
var seconds = 0.0
var distance = 0.0
var avgPace = 0.0
var minLat = 0.0
var minLng = 0.0
var maxLat = 0.0
var maxLng = 0.0
var coordinate: MKCoordinateRegion!
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var distanceLabel: UILabel!
@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var timeLabel: UILabel!
@IBOutlet weak var paceLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
configureView()
}
func configureView() {
distanceLabel.text = ("Distance: " + String(round(distance)) + " metres")
timeLabel.text = ("You ran this route in " + String(round(seconds)) + " seconds")
databaseHandle = databaseRef.child("RunList").child(runName).observe(.value, with: { (snapshot) in
let dataDict = snapshot.value as? [String: AnyObject]
let startLatData = dataDict?["startLat"]
})
databaseHandle = databaseRef.child("RunList").child(runName).observe(.value, with: { (snapshot) in
let runData = snapshot.value as? [String: AnyObject]
self.minLat = (runData?["startLat"] as? Double)!
self.minLng = (runData?["startLong"] as? Double)!
self.maxLat = (runData?["endLat"] as? Double)!
self.maxLng = (runData?["endLong"] as? Double)!
self.mapView.region = self.mapRegion()
print(self.minLat)
print(self.maxLng)
})
}
func mapRegion() -> MKCoordinateRegion {
return MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: (self.minLat + self.maxLat)/2,
longitude: (self.minLng + self.maxLng)/2),
span: MKCoordinateSpan(latitudeDelta: (self.maxLat - self.minLat)*1.1,
longitudeDelta: (self.maxLng - self.minLng)*1.1))
}
}
我相信我的纬度和长值分别在要求(-90,90)和(-180,190)之内。当我尝试设置地图区域时,为什么我的程序会崩溃?