MKMapView in UITabBarController using swift



我正在学习使用 swift 将地图放在我的 iOS 应用程序的标签栏中。
从登录页面作为"视图控制器"开始,然后继续作为"标签栏控制器"进入主菜单,并且因为它的第一个选项卡是主地图作为"MapController"下的"MKMapView"。

一开始,当我运行应用程序时,它可以正常登录,然后正常显示地图。不幸的是,当我尝试控制地图视图(添加注释、设置区域等)时,它总是崩溃(信号 SIGABRT)。

这是我在MapController中的代码.swift:

import UIKit
import MapKit
import CoreLocation
class MapController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var mainMap: MKMapView!
var manager:CLLocationManager!
override func viewDidLoad() {
    super.viewDidLoad()
    manager = CLLocationManager()
    manager.delegate = self
    manager.desiredAccuracy = kCLLocationAccuracyBest
    manager.requestWhenInUseAuthorization()
    manager.startUpdatingLocation()
    var latitude  : CLLocationDegrees = 140.997086
    var longitude : CLLocationDegrees = 43.204067
    var latDelta:CLLocationDegrees = 0.01
    var longDelta:CLLocationDegrees = 0.01
    var homeSpan:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
    var homeLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
    var theRegion:MKCoordinateRegion = MKCoordinateRegionMake(homeLocation, homeSpan)
    mainMap.setRegion(theRegion, animated: false)
    var annotation = MKPointAnnotation()
    annotation.coordinate = homeLocation
    annotation.title = "test"
    annotation.subtitle = "another test"
    mainMap.addAnnotation(annotation)

}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}

谁能帮我解决这个问题? 如果您有其他样品,那也会非常好。提前谢谢你。

此代码运行良好,纬度和经度的值除外。

最新更新