微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。