【发布时间】:2014-05-20 05:46:59
【问题描述】:
在我的应用程序中,我想做地理围栏。我有位置列表,我正在为其设置地理围栏区域。 所有位置的半径为 100m。以下是设置Region的代码:
CLLocationCoordinate2D cord;
cord.latitude = [location.latitude doubleValue];
cord.longitude = [location.longtitude doubleValue];
CLLocationDistance regionRadius = location.radius;
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:cord radius:regionRadius identifier:[NSString stringWithFormat:@"%d",location.locId]];
[appDelegate.locationManager startMonitoringForRegion:region];
我的问题是,它不能正常工作。为了调试,在 didEnterRegion 委托中添加了当前位置和区域位置之间的距离计算,有时这个距离大于 1500m。
以下是计算当前位置与区域位置之间距离的代码:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
CLLocation *loc1 = locationManager.location;
CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:region.center.latitude longitude:region.center.longitude];
double dist = [loc1 distanceFromLocation:loc2];
}
知道吗,为什么-locationManager:didEnterRegion: 会以这种错误的方式触发?
【问题讨论】:
标签: ios cllocationmanager geofencing