我试图在TableView中查看MKMapView,但它已经崩溃了一些问题,但我无法找到问题,请任何人帮我清除这个问题? 它显示像这样......
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'无效的区域中心:-119.27656620,+ 34.26884010 span:+0.04487346,-0.12825858>'
这里我给我的代码我做了什么..
let location = CLLocationCoordinate2D(
latitude: longarray[indexPath.row] as! Double,
longitude: latarray[indexPath.row] as! Double
)
print("the json array of Longitude is \(self.longarray[indexPath.row])")
print("the json array of Longitude is \(self.latarray[indexPath.row])")
let span = MKCoordinateSpanMake(2.0, 2.0)
print("the span is \(span)")
let region = MKCoordinateRegion(center: location, span: span)
cell.mapView.setRegion(region, animated: true)
let annotation = MKPointAnnotation()
annotation.coordinate = location
cell.mapView.addAnnotation(annotation)
答案 0 :(得分:6)
错误非常简单:在latitude
中你传递了经度值,对于longitude
你做了同样的事情,所以切换它们
在您的代码中:
let location = CLLocationCoordinate2D(
latitude: longarray[indexPath.row] as! Double, //<-- error
longitude: latarray[indexPath.row] as! Double //<--- error
)
纬度属性无法接收任何经度值,因为它们是负数
正确的代码应为:
let location = CLLocationCoordinate2D(
latitude: latarray[indexPath.row] as! Double,
longitude: longarray[indexPath.row] as! Double
)