“类型'(CLLocationManager,[CLLocation])->()的值没有成员'delegate'”快速映射错误

问题描述 投票:0回答:1

[尝试查找用户的位置时,我使用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 DescriptionPrivacy - Location Always and When In Use Usage Description添加到任何想知道的人。

ios swift cllocationmanager cllocation
1个回答
0
投票

添加CLLocationManagerDelegate

class MapsViewController: UIViewController,MGLMapViewDelegate,CLLocationManagerDelegate{
© www.soinside.com 2019 - 2024. All rights reserved.