ios - 我尝试向我的应用程序添加 map ,但我看到的只是黑屏......为什么?

标签 ios swift mkmapview mapkit

我试图显示 map 并为用户提供 map 中的位置,但我得到的只是黑屏。我觉得我设置正确,但它不适合我。有人在我的代码中看到不正确的内容或我忘记添加的内容吗?代码如下:

class MapScene: SKScene, CLLocationManagerDelegate, MKMapViewDelegate {

var locationMangaer = CLLocationManager()
var map : MKMapView! = MKMapView()


override func didMoveToView(view: SKView) {
    locationMangaer.delegate = self
    locationMangaer.desiredAccuracy = kCLLocationAccuracyBest
    locationMangaer.requestWhenInUseAuthorization()
    locationMangaer.startUpdatingLocation()
    locationMangaer.requestAlwaysAuthorization()

    map.showsUserLocation = true
    map.delegate = self
    map.showsBuildings = true
    map.showsPointsOfInterest = true
    map.zoomEnabled = true
    map.scrollEnabled = true
    map.zoomEnabled = true
    map.rotateEnabled = true
    map.mapType = MKMapType.Hybrid
    map.pitchEnabled = false
    map.userInteractionEnabled = true


}



//DELEGATE METHODS

func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
    println(error)
}

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {


    var userLocation: CLLocation = locations[0] as! CLLocation
    locationMangaer.stopUpdatingLocation()

    let location = CLLocationCoordinate2DMake(userLocation.coordinate.latitude, userLocation.coordinate.longitude)
    let span = MKCoordinateSpanMake(0.05, 0.05)
    let region = MKCoordinateRegion(center: location, span: span)

    self.map.setRegion(region, animated: true)


    println("call")
}

最佳答案

我让它工作......我必须添加这两行代码:

    map.frame = CGRectMake(0, 0, frame.size.width, frame.size.height - 50)
    self.view?.addSubview(map)

关于ios - 我尝试向我的应用程序添加 map ,但我看到的只是黑屏......为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32216824/

相关文章:

ios - 实现嵌入在两个独立容器 Controller 中的 View 之间的委托(delegate)

iPhone:20 分钟后 MapView 中的应用程序崩溃

iOS:如何从地标获取邮​​政编码

ios - 目标debug_ios_bundle_flutter_assets失败:

ios - -[NSString dataUsingEncoding :] gives garbage at end of string in iOS 9, 不是 iOS 8

iphone - 如何删除观察者

swift - 如何在 Swift 中检索网页的 HTML 代码

swift - performBackgroundTask() 中的 perform() 和 performAndWait() 是否需要,可以使用吗?

UIImagePicker 未设置 Swift UIButton 背景图像

iOS Today 扩展 MapView 仅适用于 Xcode 模拟器