热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CLLocationManager获取位置很慢,Swift

如何解决《CLLocationManager获取位置很慢,Swift》经验,为你挑选了1个好方法。

我正在创建这个应用程序,它需要获取用户位置 - 它一切正常,事实上,从接受使用位置服务到获取实际位置需要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连接,所以我知道它不是因为互联网很慢,或者连接不好......

有人有想法吗?:)

最好的祝福!



1> Jens Peter..:

尝试设置准确性并使用locationManager.startUpdatingLocation().我这样做,并在一秒钟内(在设备上)得到答案.


推荐阅读
author-avatar
yo繽紛樂
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有