CLLocationManager.requestLocation()大约需要10秒钟 [英] CLLocationManager.requestLocation() takes about 10 seconds

查看:167
本文介绍了CLLocationManager.requestLocation()大约需要10秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CLLocationManager.requestLocation()大约需要10秒钟触发 didUpdateLocations 事件。

CLLocationManager.requestLocation() takes around 10 seconds to fire didUpdateLocations event.

这是为 CLLocationManager

let locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = 10
locationManager.requestWhenInUseAuthorization()
locationManager.requestLocation()

根据文档,这可能需要几秒钟。

As per the documentation this can take several seconds.


此方法立即返回。调用它会导致位置管理器获取位置修复(可能需要几秒钟),并调用代理的locationManager(_:didUpdateLocations :)方法并返回结果。

This method returns immediately. Calling it causes the location manager to obtain a location fix (which may take several seconds) and call the delegate’s locationManager(_:didUpdateLocations:) method with the result.

但这可以花费10秒钟吗?还是我错过了什么?

But can this take 10 long seconds? Or am I missing something?

推荐答案

如果您退出

locationManager.requestLocation()

用于

locationManager.startUpdatingLocation() 

然后 didUpdateLocations 将立即开始触发。这应该可以解决您的问题。

then didUpdateLocations will start firing immediately. This should solve your problem.

这篇关于CLLocationManager.requestLocation()大约需要10秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆