- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我已经设置了委托(delegate),创建了一个区域,并且我已经阅读了所有文档。每次用户的位置发生变化并且在指定区域之外时,都不会调用 locationManager(manager: CLLocationManager, didExitRegion region: CLRegion)
。我见过它被调用一次然后就停止了。我花了很多时间试图弄清楚发生了什么。
快速了解我在做什么:
当应用程序启动时,我调用 locationManager.startUpdatingLocation()
,后者又调用委托(delegate) locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
,我这样做向服务器快速请求一些我需要的信息,创建一个 CLCircularRegion
并继续调用 locationManager.stopUpdatingLocation()
。在那个方法中,我调用了我的 startMonitoringForRegion(_:)
。
可能是因为每次我创建一个新区域时它都使用相同的标识符? Apple 的文档说可以使用相同的标识符,因为它会替换之前的标识符,但我想知道这是否会导致委托(delegate)不调用 didExitRegion
。
我的代码如下。谢谢你。
func configureLocation() {
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.allowsBackgroundLocationUpdates = false
locationManager.pausesLocationUpdatesAutomatically = true
// Distance filter to update location
//locationManager.distanceFilter = 10.0
// Begin updating user location
locationManager.startUpdatingLocation()
} else {
let title = "Location disabled"
let message = "To enable location services go to Settings > Privacy > Location Services"
self.locationServicesAlertMessage(title, message: message)
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("didUpdateCalled")
/*
if UIApplication.sharedApplication().applicationState == .Active {
print("ACTIVE UPDATE: location")
} else if UIApplication.sharedApplication().applicationState == .Background {
print("BACKGROUND UPDATE: location")
}
*/
if firstLocationUpdate {
let center = CLLocationCoordinate2D(latitude: (manager.location?.coordinate.latitude)!, longitude: (manager.location?.coordinate.longitude)!)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpanMake(0.01, 0.01))
self.mapView.setRegion(region, animated: true)
self.firstLocationUpdate = false
}
// If the user is travelling less than 5 mph, update location
if manager.location?.speed <= 3.5 {
self.updateLongAndLat(manager.location!) { (lat, long) in
print("LAT: \(lat)")
print("LONG: \(long)")
if lat != nil && long != nil {
let center = CLLocationCoordinate2D(latitude: lat!, longitude: long!)
let monitoredRegion = CLCircularRegion(center: center, radius: 10.0, identifier: "UserRegion")
monitoredRegion.notifyOnEntry = false
self.locationManager.startMonitoringForRegion(monitoredRegion)
self.locationManager.stopUpdatingLocation()
}
}
}
}
func locationManager(manager: CLLocationManager, didExitRegion region: CLRegion) {
print("EXITED REGION")
print("Identifier: \(region.identifier)")
if manager.location?.speed <= 3.5 {
self.updateLongAndLat(manager.location!, completion: { (lat, long) in
if lat != nil && long != nil {
let center = CLLocationCoordinate2D(latitude: lat!, longitude: long!)
let monitoredRegion = CLCircularRegion(center: center, radius: 10.0, identifier: "UserRegion")
self.locationManager.startMonitoringForRegion(monitoredRegion)
}
})
}
}
最佳答案
区域监控不依赖于 GPS。这是蜂窝塔/wifi 接入点三角测量。您不应期望水平精度优于 65m。试图用 65 米精度的仪器检测 10 米的运动根本行不通。
我不知道iOS在被要求监控半径小于100m的区域时做了什么。充其量它只是将半径增加到 100。在这种情况下,您的应用仍然可以工作,但可能不是它预期的方式。
要从评论中回答您的问题,恐怕 Apple 没有提供对其核心定位技术的深入见解。这就是开发人员之间存在很多困惑的原因,因为似乎没有任何东西能按预期工作。对于初学者来说,核心位置 API 旨在实现最佳实践以最大程度地减少电池消耗。
如果您想使用小于 ~300 米(是的,三百米)的定位服务,则必须使用 GPS。地理围栏无法跟上不断行走的用户的步伐。但是,在后台持续运行 GPS 是不行的,因为你会很快耗尽电池,你的应用程序很快就会从用户手机中退出。
地理围栏不需要 GPS,但会很乐意使用可用的 GPS 数据(即使 GPS 更新是由另一个应用程序请求的)。 GPS 辅助地理围栏的工作非常精确,但我看不出有什么好的理由同时使用这两种服务,因为只需将位置管理器过滤器设置到正确的距离就更简单了。
关于ios - 位置管理器 didExitRegion 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36486202/
我会尽可能地解释我正在做的事情,以获得最好的可能的建议/解决方案。这一切都是在 java 中完成的。 我的客户有一个基于 SWING 的桌面应用程序,它将使用 WebStart 加载。我被指派为用户帐
看来这个page包含 Azure CLI 支持的与 Azure API 管理相关的所有功能。但它没有展示如何使用 Azure CLI 管理用户、产品、证书、订阅和 API 等实体。 Azure CLI
我设置了一个 Hadoop 1.2.x 版本,双节点集群。第一节点(NameNode、Jobtracker)和第二节点(Secondary NameNode、Datanode、TaskTracker)
对于内容驱动的网站,设计好坏的关键是关系型数据库。在这个教程中,我们已经使用了MySQL关系型数据库管理系统(RDBMS)建立了我们的数据库。对于网站的开发者来说,MySQL是一个较受欢迎的选择,这
在尝试运行MariaDB之前,首先确定其当前状态,运行或关闭。 有三个选项用于启动和停止MariaDB – 运行mysqld(MariaDB脚本)。 运行mysqld_safe启动脚本。
我在管理界面中遇到 StackedInlines 前缀的问题。我会尝试发布所有必要的代码。 models.py(简要) ##### Base classes class BaseItem(models
我是新来的。到目前为止,我一直在使用 MVC 模型并使用基本的 session 管理模型,即在 session 中存储一个 token 并检查每个请求。 我正在尝试对lift做同样的事情,但我的 se
我在 win 服务中使用 NHiberante。有时我得到 System.ObjectDisposedException: Session is closed! Object name: 'ISess
我正在尝试使用 HtmlUnit 登录 Facebook 页面并查看其 HTML 内容。我正在尝试通过 HtmlUnit 填写登录凭据,但在单击提交按钮时我没有看到正在执行的 session 。 在
我正在为一个相当大的项目开发一个带有 reactjs 的前端,该项目有两个主要接口(interface)。主站点的前端和管理员的前端。 我应该将它们开发为两个不同的项目还是 reactjs 中的一个项
短版 我有一个使用插件基础结构的应用程序。插件具有可配置的属性,可帮助它们了解如何完成工作。插件按配置文件分组以定义如何完成任务,配置文件存储在由 DataContractSerializer 序列化
如何管理 iPhone 应用程序中的用户 session ?我在应用程序的第一页上从用户那里获取了用户名和密码。用户可以随时注销。如何像其他 Web 应用程序一样在 iPhone 应用程序中存储 se
我正在使用 Azure API 管理,其中包含第三方论坛 (Discourse) 的链接。 api管理提供的默认登录系统用于注册用户。我想知道是否可以对 api 管理和论坛使用单点登录,这样用户就不必
我正在使用 Wordpress 建立一个网站,并且我想利用它的 session 。但我没有找到任何插件,甚至文档。在我开始破解之前有什么建议或引用吗? 注意:我问的是 WP 是否以及如何使用标准 PH
我已阅读《Azure in Action》一书中的以下内容:“在 Windows Azure 中,状态服务器或进程外 session 状态提供程序,不支持” 谁能告诉我为什么不支持这个。他们在书中没有
我有一个内联表单集,我想排除一些模型对象在表单集中显示。 例如。模型 B 具有模型 A 的外键,因此它是 1:n(A 对象有许多 B 对象)关系。现在在 A 管理编辑页面上,我已经获得了 B 的内联。
我正在开发一个基于 session 的项目。我在想,与银行类似,我会创建一张支票并为用户提供阻止 session 超时的能力。 我正在考虑创建一个 setInterval 来检查需要身份验证的空白页面
我正在为一位拥有 Magento 商店的客户工作。里面塞满了产品,但这些产品的名称有点乱。他并没有坚持一种命名约定,而是多年来使用了不同的约定。因此,每当他使用“管理”->“管理产品”部分中的“名称”
我使用大约十几个 XSLT 文件来提供大量输出格式。目前,用户必须知道导出的文件格式的扩展名,例如RTF、HTML、TXT。 我还想使用参数来允许更多选项。如果我可以将元数据嵌入 XSL 文件本身,那
我已阅读《Azure in Action》一书中的以下内容:“在 Windows Azure 中,状态服务器或进程外 session 状态提供程序,不支持” 谁能告诉我为什么不支持这个。他们在书中没有
我是一名优秀的程序员,十分优秀!