您好我刚开始学习swift ios-9。 我正在使用以下代码来获取用户的当前位置,但它正在获取位置
<+37.78583400,-122.40641700> +/- 5.00m (speed -1.00 mps / course -1.00) @ 1/8/16, 3:38:10 PM Greenwich Mean Time
输出中没有在地图上显示我当前的位置。
Swift Code:
class ViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {
@IBOutlet weak var map: MKMapView!
var manager:CLLocationManager!
override func viewDidLoad()
{
super.viewDidLoad()
manager = CLLocationManager()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestWhenInUseAuthorization()
manager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print(locations[0])
//userLocation - there is no need for casting, because we are now using CLLocation object
let userLocation:CLLocation = locations[0]
let latitude:CLLocationDegrees = userLocation.coordinate.latitude
let longitude:CLLocationDegrees = userLocation.coordinate.longitude
let latDelta:CLLocationDegrees = 0.01
let lonDelta:CLLocationDegrees = 0.01
let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)
let location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
map.setRegion(region, animated: true)
}
}
我还将CoreLocation.framawork链接到我的项目。 正如我刚开始学习的那样,我没有Apple的开发者许可证。