【发布时间】:2015-05-29 19:39:02
【问题描述】:
我有一个将兴趣点 (POI) 存储在核心数据 managedObjectContext 中的应用。我的目标是在currentLocation 位于managedObjectContext 中的 POI 的指定范围内时发出警报。在阅读CLRegion 时,似乎可以监控的区域数量上限为 20。
为了绕过区域监控上限,我的游戏计划是在每次我的位置经理的didUpdateLocations 在我的应用程序中触发时,浏览我的managedObjectContext 以获取纬度/经度坐标并计算 POI 之间的距离:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *location = [locations lastObject];
NSLog(@"LocationManager Latitude %+.6f, Longitude %+.6f\n",
location.coordinate.latitude,
location.coordinate.longitude);
// TODO: compute distances between objects in managedObjectContext
[self calculateDistances];
self.currentLocation = location;
}
// method to compute distances
- (void) calculateDistances {
// for POI in managedObjectContext, do the following
CLLocation *locA = [[CLLocation alloc] initWithLatitude:self.currentLocation.coordinate.latitude longitude:self.currentLocation.coordinate.longitude];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:POIlatitude longitude:POIlongitude];
CLLocationDistance distance = [locA distanceFromLocation:locB];
if (distance < 1000) {
// popup alert
}
}
我只使用managedObjectContext 来显示数据。在这种情况下,我没有显示任何内容——相反,我只是在didUpdateLocations 触发时穿过我的MOC 中的对象,提取坐标并计算距离。任何想法如何做到这一点?
【问题讨论】:
-
我不确定我是否理解这个问题。如果您不想显示数据,请不要执行任何将其显示在屏幕上的代码。哪一部分没有意义?
-
我更新了我的帖子以增加说明。
标签: core-data ios8 cllocationmanager geofencing