【发布时间】:2017-12-06 07:01:05
【问题描述】:
我得到了用户的当前位置,但是在这一行得到了这个错误
let region : MKCoordinateRegion = MKCoordinateSpanMake(myLocation, span)
我在上面一行的 myLocation 处遇到错误
无法将“CLLocationCoordinate2D”类型的值转换为预期的参数类型“CLLocationDegrees”(又名“Double”)
我认为可能存在类型转换问题或类似问题。
我应该怎么做才能处理这个错误我研究了很多例子,但没有一个对我有帮助。
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
let manager = CLLocationManager()
@IBOutlet weak var myMap: MKMapView!
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations[0]
let span : MKCoordinateSpan = MKCoordinateSpanMake(1, 1)
let myLocation : CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
let region : MKCoordinateRegion = MKCoordinateSpanMake(myLocation, span)
myMap.setRegion(region, animated: true)
self.myMap.showsUserLocation = true
}
override func viewDidLoad() {
super.viewDidLoad()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestWhenInUseAuthorization()
manager.startUpdatingLocation()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
【问题讨论】:
标签: ios swift mapkit core-location