- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
//code for adjusting pins location when user re-enters its radius
}
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
//code for adding pin to map
}
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
}
- (CLRegion*)dictToRegion:(NSDictionary*)dictionary
{
NSString *identifier = [dictionary valueForKey:@"identifier"];
CLLocationDegrees latitude = [[dictionary valueForKey:@"latitude"] doubleValue];
CLLocationDegrees longitude =[[dictionary valueForKey:@"longitude"] doubleValue];
CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(latitude, longitude);
CLLocationDistance regionRadius = [[dictionary valueForKey:@"radius"] doubleValue];
if(regionRadius >_locationManager.maximumRegionMonitoringDistance)
{
regionRadius =_locationManager.maximumRegionMonitoringDistance;
}
NSString *version = [[UIDevice currentDevice] systemVersion];
CLRegion * region =nil;
if([version floatValue] >= 7.0f) //for iOS7
{
region = [[CLCircularRegion alloc] initWithCenter:centerCoordinate
radius:regionRadius
identifier:identifier];
}
else // iOS 7 below
{
region = [[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate
radius:regionRadius
identifier:identifier];
}
return region;
}
所以我试图这样做,以便当iBeacon离开被监视的区域(这总是用户手机周围的区域)时,它还会创建一个地图注释/引脚,从而标记其最后的已知位置。任何人都可以帮助或指出我正确的方向吗?
答案 0 :(得分:1)
iBeacon实际上是地理围栏。您定义CLBeaconRegion
,然后像CLCircularRegion
一样监视区域的进入/退出。与CLCircularRegion
不同,CLBeaconRegion
是根据iBeacons UUID 和可选的主要和次要值定义的。
当iBeacon可见/不再可见时,您会收到代表的didEnterRegion
和didExitRegion
方法的电话 - Location and Maps Programming Guide
您无法获得信标的位置,但当您退出该区域时,您可以捕获设备的GPS位置,作为上次看到信标的大致位置。一旦你有了,那么创建一个地图注释是微不足道的。