加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

CLLocationManager获取位置很慢,Swift

发布时间:2020-12-14 04:49:40 所属栏目:百科 来源:网络整理
导读:我正在创建这个应用程序,它需要获取用户位置 – 它一切正常,事实上,从接受使用位置服务到获取实际位置需要5秒的时间 – 这是正常的吗? 我使用过其他应用程序,速度更快.. 这是我的代码的样子: override func viewDidLoad() { super.viewDidLoad() // Ask fo
我正在创建这个应用程序,它需要获取用户位置 – 它一切正常,事实上,从接受使用位置服务到获取实际位置需要5秒的时间 – 这是正常的吗?
我使用过其他应用程序,速度更快..

这是我的代码的样子:

override func viewDidLoad() {
    super.viewDidLoad()

    // Ask for Location-Authorisation from the User.
    self.locationManager.requestWhenInUseAuthorization()

    if CLLocationManager.locationServicesEnabled() {
        locationManager.delegate = self
        locationManager.requestLocation()
    }

    mapView.delegate = self

}



func locationManager(manager: CLLocationManager,didUpdateLocations locations: [CLLocation]) {
    let locValue: CLLocationCoordinate2D = manager.location!.coordinate

    let initialLocation = CLLocation(latitude: locValue.latitude,longitude: locValue.longitude)

    self.centerMapOnLocation(initialLocation)
}

func locationManager(manager: CLLocationManager,didFailWithError error: NSError) {
    print("could not get location")
}

但是从应用程序获取位置放入centerMapOnLocation函数的时间似乎只是很长.获取用户位置时会出现什么情况?我正在测试一个wifi连接,所以我知道它不是因为互联网很慢,或者连接不好……

有人有想法吗?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读