我试图显示 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/