- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
为什么位置管理器不止一次调用 startUpdatingLocation
?有时调用一次,有时调用三次。我不知道为什么;也许你可以帮助我。我有来自 GitHub 的代码。
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate
{
let locationManager = CLLocationManager()
override func viewDidLoad()
{
super.viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: {(placemarks, error) -> Void in
if (error != nil)
{
print("Error: " + error!.localizedDescription)
return
}
if placemarks!.count > 0 {
if let pm = placemarks?.first {
self.displayLocationInfo(pm)
}
}
else
{
print("Error with the data.")
}
})
}
func displayLocationInfo(placemark: CLPlacemark)
{
self.locationManager.stopUpdatingLocation()
print(placemark.locality)
print(placemark.postalCode)
print(placemark.administrativeArea)
print(placemark.country)
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError)
{
print("Error: " + error.localizedDescription)
}
}
最佳答案
是的,这是标准行为。当您开始定位服务时,随着设备“预热”,您通常会收到一系列越来越准确的 CLLocation
更新(即 horizontalAccuracy
随着时间的推移而减少)。例如,它可能会开始报告它可能已经基于手机信号塔的位置信息,但随着 GPS 芯片获得更多信息,它可以更好地对您的位置进行三角测量,它会为您提供更新。等等
如果你想减少这种行为,你可以结合使用更大的distanceFilter
、更低的desiredAccuracy
,或者调用一次stopUpdatingLocation
你得到一个你将进行地理编码的位置。
现在您正在调用 stopUpdatingLocation
,但您是从异步调用的 reverseGeocodeLocation
闭包中执行此操作的。这意味着在调用 reverseGeocodeLocation
的完成处理程序之前,可以插入更多位置更新。如果您同步调用 stopUpdatingLocation
(例如,在 reverseGeocodeLocation
之前),那么您将避免这种行为。
关于swift - 为什么 LocationManager 会多次调用 startUpdatingLocation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32051873/
我的问题很简单: 这些可以吗: manager.delegate = self; [manager startUpdatingLocation]; return self; 作为 -init 方法的最
我创建了一个方法来检查授权是否正确,但是除此之外,即使授权正确,也不意味着它可以检索位置。我试图在 didFailWithError 中检查它,但它似乎被调用了两次,这使得很难发出任何类型的错误消息这
我一直在尝试获取位置坐标。在我调用 [locationManager startUpdatingLocation]; 之后没有任何反应。 它从不调用 - (void)locationManager:(
我有关于显着变化位置服务的问题。 Apple 文档说“无论您使用标准定位服务还是重大更改定位服务来获取定位事件,您接收这些事件的方式都是相同的。” 但是在“显着变化的位置服务”的情况下,我无法获得任何
对于为什么应该使用startUpdatingLocation来定位信标,我没有令人信服的答案。在后台监视/定位信标或在用户已经在区域中并开始监视信标时获取通知是否需要?出现在帖子中,说这实际上会增加电
我有一个需要在后台连续更新GPS的应用程序。我已将其命名为startUpdatingLocation,并设置了“用于位置更新的应用程序注册”,并且得到了大约15分钟的修复,然后该应用程序停止获取更新。
我注意到,在我的应用程序中,当我调用 startUpdatingLocation 时,我的 UI 会短暂锁定,同时我假设设备正在收集位置数据。这是典型的吗?有什么方法可以限制这种情况吗?这就是我的代码
我有一个特定的用例,我希望能够在应用程序已在后台时启动位置更新。具体来说,我希望能够按下我的 Pebble watch 应用程序上的一个按钮,这会导致我的配套 iOS 应用程序开始位置更新。 仅当 i
我正在尝试使用 CLLocation。每次我尝试调用 startUpdatingLocation() 方法时,当前纬度和经度的值始终为零。我在 viewDidLoad() 函数中包含了 locatio
我需要知道我是否靠近我的应用程序中保存的地理位置,范围从10 米 到500 米 在后台。我使用了 startMonitoringForSignificantLocationChange 但我没有得到准
{ ... locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; l
所以现在我至少得到了以下代码的回调...... - (void)viewDidLoad { [super viewDidLoad]; mapView=[[MKMapView alloc] initWi
我正在尝试更改 MapView 的初始缩放位置。如果 myLocation == false,我希望初始位置为 (35,35),如果为 true,则获取当前位置。但是 startUpdatingLoc
我创建了一个应用程序 (Swift 4.0),当它接近 iBeacon 时,它会通过 startUpdatingLocation() 启动本地化。一切都很完美,无论是在前台、后台还是被杀死的应用程序。
这个问题在这里已经有了答案: StartUpdateLocations in Background, didUpdatingToLocation only called 10-20 times (
我正在尝试编写一个简单的地理定位应用程序来查找用户在 iOS 中的位置。当用户按下按钮时,会找到并显示用户的位置,并且应该在触发 startUpdatingLocation 时更改。但是 startU
我正在尝试使用 CLLocationManager 获取用户的当前位置。一切正常,但是在应用程序查找位置时有一点延迟,我需要等待它完成才能允许用户发送它。 [locationManager start
我正在创建需要在特定时间在后台唤醒的应用。 我试过了: UILocalNotification:但我不想使用 UILocalNotification,因为它需要用户交互才能点击通知,而且只有应用程序会
我一直在关注这个教程http://www.devfright.com/ios-6-core-location-tutorial/将位置服务添加到我的 ios 应用程序。我在我的 TestFileVie
override func awakeWithContext(context: AnyObject?) { super.awakeWithContext(context) // Con
我是一名优秀的程序员,十分优秀!