我正在尝试将地图添加到我的应用程序,但我看到的只是黑屏......为什么?
Im trying to add a map to my app but all I see is a black screen.....Why?
我试图显示地图并在地图中为用户提供位置,但我得到的只是黑屏。我觉得我设置正确但它不适合我。有没有人在我的代码中看到不正确的东西或我忘记添加的东西?这是代码:
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)
我试图显示地图并在地图中为用户提供位置,但我得到的只是黑屏。我觉得我设置正确但它不适合我。有没有人在我的代码中看到不正确的东西或我忘记添加的东西?这是代码:
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)