我创建了一个基于地理围栏跟踪GPS位置的示例应用程序。首先,我创建了一个地理围栏并将其添加到监控中,使用相同的位置在MapView上放置一个圆形覆盖。
CLLocationCoordinate2D centerCoordinate1 = CLLocationCoordinate2DMake(23.518192, 72.337122);
CLCircularRegion *region1 =[[CLCircularRegion alloc] initWithCenter:centerCoordinate1 radius:100 identifier:@"Location First"];
NSLog(@"%@",[region1 description]);
region1.notifyOnEntry=YES;
region1.notifyOnExit=YES;
[self.locationManager startMonitoringForRegion:region1];
NSLog(@"Started Monitoring- %@", [region1 description]);
[self.mapview setShowsUserLocation:YES];
[self.mapview setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
// create circle around monitor region and check if worker location is changed
MKCircle *circle1 = [MKCircle circleWithCenterCoordinate:centerCoordinate1 radius:100];
[self.mapview addOverlay:circle1];
现在,我正在通过Debug->Location->Custom Locations
更改模拟器位置来测试模拟器中的不同坐标。
如果我更改了主要的lat-long,那么它将调用区域的进入/退出方法,但是如果我在+/-
附近按位置检查纬度和经度的10 or 20
点,则重复进行。
First Image which is inside the GeoFence
Another Image which is outside the GeoFence
另一幅图像在GeoFence外部可见,但在设置此纬度和经度时,它不会调用region exit
方法。
以下是区域监测方法
-(void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region;
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region;
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region;
我正在同时添加4到5个区域进行监控。
任何帮助都将受到高度赞赏。