位置感知:靠近坐标时的通知

时间:2013-06-12 02:06:46

标签: ios objective-c maps

我有一个用于注释的多个坐标数组。我正在尝试制作一个功能,所以当有人开车时,他们在任何一个点的1000米范围内,通过电话弹出警报(如果应用程序在后台运行,就像本地通知一样)说:“你是靠近%@“

寻找最佳方法,

提前致谢

1 个答案:

答案 0 :(得分:0)

请参阅位置感知编程指南中的Monitoring Shape Based Region

- (BOOL)registerRegionWithCircularOverlay:(MKCircle*)overlay andIdentifier:(NSString*)identifier
{
   // Do not create regions if support is unavailable or disabled
   if ( ![CLLocationManager regionMonitoringAvailable])
      return NO;

   // Check the authorization status
   if (([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorized) &&
      ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusNotDetermined))
      return NO;

   // Clear out any old regions to prevent buildup.
   if ([self.locManager.monitoredRegions count] > 0) {
      for (id obj in self.locManager.monitoredRegions)
         [self.locManager stopMonitoringForRegion:obj];
   }

   // If the overlay's radius is too large, registration fails automatically,
   // so clamp the radius to the max value.
   CLLocationDegrees radius = overlay.radius;
   if (radius > self.locManager.maximumRegionMonitoringDistance) {
      radius = self.locManager.maximumRegionMonitoringDistance;
   }

   // Create the region to be monitored.
   CLRegion* region = [[CLRegion alloc] initCircularRegionWithCenter:overlay.coordinate
                         radius:radius identifier:identifier];
   [self.locManager startMonitoringForRegion:region];
   return YES;
}