此代码功能较早,现在它一直在崩溃,因为该位置将返回为零。我不确定此错误的来源或解决方法。据我所知,我的代码是正确的。有什么帮助吗?
import UIKit
import CoreLocation
import MapKit
class LocationController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {
var locationManager = CLLocationManager()
@IBOutlet var Map: MKMapView!
var manager:CLLocationManager!
var myLocations: [CLLocation] = []
override func viewDidLoad()
{
super.viewDidLoad()
self.Map.mapType = MKMapType.Standard
self.Map.showsUserLocation = true
//self.Map.removeAnnotations(self.theMap.annotations)
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
let location = self.locationManager.location
var latitude: Double = location.coordinate.latitude
var longitude: Double = location.coordinate.longitude
println("current latitude :: \(latitude)")
println("current longitude :: \(longitude)")
}
答案 0 :(得分:0)
location
的{{1}}属性声明为:
CLLocationManager
因此您的@NSCopying var location: CLLocation! { get }
可以填充let location
值。也许这个声明最近发生了变化,因为Apple磨损了与选项相关的界面。
您需要在尊重可能nil
的同时绑定latitude
和longitude
。