swift5使用未声明的类型'CLLocaitonDegress'

问题描述

我试图从我的应用程序中获取经度和纬度的值。 但此消息出现“使用未声明的类型'CLLocaitonDegress'的错误”。 我不明白我的代码怎么了?

func fetchWeather(latitude: CLLocaitonDegress,longitude: CLLocationdegrees) {
        let urlString = "\(weatherURL)&lat=\(latitude)&lon=\(longitude)"
        performRequest(urlString: urlString)
    }

//MARK: -CLLocationManagerDelegate

extension WeatherViewController: CLLocationManagerDelegate {
    func locationManager(_ manager: CLLocationManager,didUpdateLocations locations: [CLLocation]) {
        if let location = locations.last {
            let lat: Double = location.coordinate.latitude
            let lon: Double = location.coordinate.longitude
            weatherManager.fetchWeather(cityName: String,latitude: lat,longitude: lon)
        }
    }
    
    func locationManager(_ manager: CLLocationManager,didFailWithError error: Error) {
        print("error")
    }
    
}


解决方法

替换您的代码: func fetchWeather(纬度:CLLocaitonDegress,经度:CLLocationDegrees)

与此:

func fetchWeather(纬度:CLLocationDegrees,经度:CLLocationDegrees)

,

您需要在导入UIKit下添加导入CoreLocation

import UIKit
import CoreLocation