- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在实现 startMonitoringFromRegion:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
self.currentLocation = newLocation;
if (![CLLocationManager regionMonitoringAvailable] ||
![CLLocationManager regionMonitoringEnabled])
return;
CLLocationDegrees radius = 5;
if (radius > self.locationManager.maximumRegionMonitoringDistance)
radius = self.locationManager.maximumRegionMonitoringDistance;
CLRegion* region = [[CLRegion alloc] initCircularRegionWithCenter:self.currentLocation.coordinate
radius:radius
identifier:@"Indentifier"];
[self.locationManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyHundredMeters];
[region release];
}
当我进入一个新区域时,didEnterRegion 将被调用。我的问题是,我应该在 didEnterRegion 中做什么?
我有一个包含所有坐标的数组。我应该提取region.center并将该坐标与我的坐标数组进行比较,然后查看哪一个坐标最接近region.center?
最佳答案
我注意到 CLRegion 有一个很棒的方法,称为 containsCooperative。
因此,我现在可以只使用 containsCoordinate,而不是循环遍历 didEnterRegion 中的所有麦当劳数组坐标并检查它们距 Region.center 的距离是否小于 x 公里。
for (Restaurant *restaurant in arrRestaurants)
{
CLLocation *restaurantLocation = [[CLLocation alloc] initWithLatitude:[resturant.latitude doubleValue] longitude:[restraurant.longitude doubleValue]];
if ([region containsCoordinate: restaurantLocation.coordinate])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"McDonads found in the region!" message:[NSString stringWithFormat:@"%@", restaurant.town] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
}
现在,我还没有尝试过,但对我来说这似乎是合乎逻辑的。
关于ios - startMonitoringFromRegion - 在 didEnterRegion 中做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7147942/
我在iOS和gefencing方面遇到了一些问题...... // // ViewController.m // // // Created by me on 14.05.13. // Cop
所以我问了一个关于我与 didEnterRegion 相关的代码的问题,但也许我太具体了,因此我可以请人用更通用的术语来澄清方法调用的顺序以进行区域监控,特别是当应用程序在后台时。 我的理解是: 应用
在 appDelegate 中,我有一个信标管理器和 3 个信标区域,每个区域都使用相同的 UUID 初始化,但具有不同的主次区域。我在每个信标区域上调用了 startMonitoringForReg
iOS5。我已经正确设置了 CLLocationManager,它会监听区域进入/退出。一切正常。但是当我终止我的应用程序并进入一个区域时,我收到了一个本地通知(在 didEnterRegion 方法
我写了下面的代码,这是我能想到的最基本的 Swift 3 代码,用于检查我的应用程序是否可以检测 iBeacon 是否可用。然而,didEnterRegion 只在极少数情况下启动一次。我大概在我的手
我在我的应用中使用由 iBeacon 触发的本地通知。只要 iPhone 处于事件状态,它在前台和后台都能正常工作,但在大约 15 分钟不活动或重启后不会触发 didEnterRegion。 然后它只
当 GPS 进入定义的区域时,我所有的地理围栏都会触发,起初我以为是因为半径,但即使在减半后我也遇到了同样的问题。 import UIKit import CoreLocation class ite
我正在开发一个关于基于位置的提醒的项目。我使用了 CoreLocation 的 didEnterRegion 方法。因此,当我设置输入区域的位置时,我可以收到通知,但每当我想使用 didEnterRe
我已经实现了区域监控并且运行良好。我的测试应用程序在应用程序启动时开始监视一个区域,我调用 startUpdatingLocation 更新 map 上的图钉以可视化我所在的位置。然后,使用XCode
这是基于iBeacon Bluetooth didEnterRegion and didExitRegion methods are never fired中问题的进一步问题已经解决了。 具体来说,d
我目前正在监控几个由核心数据支持的地点。换句话说,我已经设置了一个 for 循环,循环遍历核心数据中所有存储的实体,并为所有实体创建一个监控区域。 这里的问题是for循环在进入其中一个区域时会触发多个
我一直在试验区域监控,以便在用户位于设定区域内时显示警报或本地通知。作为第一步,我添加了一个打印行以查看它是否适用于调试区域。但是,在打印其他行时,我没有得到 didEnterRegion 和 did
我在玩 CLLocaitonManager 时遇到了非常奇怪的情况...... manager = [[CLLocationManager alloc] init]; [manager setDist
出于某种奇怪的原因,有时当我进入一个区域时,didEnterRegion 会被触发多达 10 次。有谁知道发生这种情况的可能原因是什么?我知道如果我处于边界可能会发生这种情况,但也许 Apple 有智
我已经使用 ibeacons 设置了一个应用程序,我注意到当我在该区域内打开蓝牙时,didEnterRegion 永远不会被触发。但是,当我在打开蓝牙的情况下实际进入该区域时,它工作正常。 在前台时,
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region 仅当对应于实现 CLLoc
我希望更精确地调用 didEnterRegion,但我做不到。这是我所做的:我使用了 distanceFilter 和 desiredAccuracy 的最佳值(根据 Apple 的最精确的 GPS
我制作了一个注册信标区域并使用 CLLocationManager 开始监控这些区域的应用 CLLocationManager *manager = [[CLLocationManager alloc
我一直在阅读有关 CLBeaconRegion 的文章,我已经成功地设置了一些 iBeacons 并让它触发了位置更新,即使应用程序在后台也是如此。 但是,根据我从 CLRegion 阅读和继承的内容
我在我的 iOS 应用程序中使用位置服务,即区域监控,这是我的代码 //this for creating region -(void)createRegion { [dictionary s
我是一名优秀的程序员,十分优秀!