[尝试查找用户的位置时,我使用CLLocationManager()。它向我返回此错误:Value of type '(CLLocationManager, [CLLocation]) -> ()' has no member 'delegate'
行下的locationManager.delegate = self
import CoreLocation
import UIKit
import SwiftUI
import Mapbox
class MapsViewController: UIViewController,MGLMapViewDelegate{
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled(){
locationManager.delegate = self //this is where I get the error said above
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
print("locations = \(locValue.latitude) \(locValue.longitude)")
}
}
我已经尝试过关于stackoverflow的错误并自己解决,但是到目前为止,没有任何帮助。 swift和XCode的新版本可能有问题(因为我正在关注this教程)
我将info.plist中的Privacy - Location When In Use Usage Description
和Privacy - Location Always and When In Use Usage Description
添加到任何想知道的人。
添加CLLocationManagerDelegate
class MapsViewController: UIViewController,MGLMapViewDelegate,CLLocationManagerDelegate{