2013-05-15 14 views

回答

2

首先,您需要使用創建區域:

CLLocationDegrees latitude = <YOUR_LATITUDE>; 
CLLocationDegrees longitude = <YOUR_LONGITUDE>; 

CLLocationCoordinate2D center = CLLocationCoordinate2DMake(latitude, longitude); 

CLLocationDistance radius = GEO_FENCE_RADIUS; 

CLRegion *region = [[CLRegion alloc]initCircularRegionWithCenter:center radius:radius identifier:title]; 

接下來,您必須監控由區域:

[locationManager startMonitoringForRegion:region]; 

然後,當他們由以下代表進入或退出,您可以跟蹤用戶方法:

- (void)locationManager:(CLLocationManager *)manager 
     didEnterRegion:(CLRegion *)region { 

     //Show your alert as they are entered the region 

} 
- (void)locationManager:(CLLocationManager *)manager 
      didExitRegion:(CLRegion *)region { 
    //Show your alert as they are exited the region 

} 

- (void)locationManager:(CLLocationManager *)manager 
didStartMonitoringForRegion:(CLRegion *)region { 


} 

- (void)locationManager:(CLLocationManager *)manager 
monitoringDidFailForRegion:(CLRegion *)region 
       withError:(NSError *)error { 


} 
相關問題