Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios7 当前位置iOS 7的区域监视_Ios7_Xcode5_Core Location_Geofencing_Region Monitoring - Fatal编程技术网

Ios7 当前位置iOS 7的区域监视

Ios7 当前位置iOS 7的区域监视,ios7,xcode5,core-location,geofencing,region-monitoring,Ios7,Xcode5,Core Location,Geofencing,Region Monitoring,我想做一个应用程序,给我一个进入和退出警告消息,当前位置与10米半径。这是我的密码: -(void)startLocationServices { if (self.locationManager == nil) { self.locationManager = [CLLocationManager new]; } [self.locationManager setDelegate:self]; [self.locationManager

我想做一个应用程序,给我一个进入和退出警告消息,当前位置与10米半径。这是我的密码:

-(void)startLocationServices
{
    if (self.locationManager == nil)
    {
        self.locationManager = [CLLocationManager new];
    }
    [self.locationManager setDelegate:self];
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [self.locationManager setDistanceFilter:kCLDistanceFilterNone];
    [self.locationManager startUpdatingLocation];
}

-(void)stopLocationServices
{
    [self.locationManager stopUpdatingLocation];
    [self.locationManager setDelegate:nil];

    //self.locationUpdateTextView.text = @"Location Service stop";
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self startLocationServices];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    self.locationUpdateTextView.text = [@"New Location: \n\n" stringByAppendingFormat:@"%@ \n \nCurrent Position\nLatitude: %f \nLongitude: %f", [locations lastObject], self.locationManager.location.coordinate.latitude, self.locationManager.location.coordinate.longitude];

    CLLocationCoordinate2D center = CLLocationCoordinate2DMake(locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude);

    CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:center radius:10.0 identifier:@"Test"];

    [self.locationManager startMonitoringForRegion:region];
    [self stopLocationServices];
}

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Status" message:@"You Enter the region" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];

    [alertView show];
}

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Status" message:@"You Exit the region" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];

    [alertView show];
}

- (void) locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
    self.availabilityTextView.text = [@"\nError:" stringByAppendingFormat:@"%@", error];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

我调用
[self-stopLocationServices]didUpdateLocations
方法中的code>,以便它获取用户的当前位置,设置半径,然后停止。当我运行应用程序并移动10米时,它不会发出任何警报消息,尽管我穿过10米半径。相反,我是随机得到的,尤其是当我穿越10米半径重新启动应用程序时。我知道在这种情况下手机发射塔的问题,但我不确定我的想法在这种情况下是否准确可行。如果有人了解我的问题并知道任何解决方案,请与我分享。

Hi@t即使我有相同的问题,也已解决此问题。请使用更新的代码让我知道您可以创建CLCircularRegion并使用StartMonitoring for Region of location manager。当您进入/退出区域代表时,将调用didEnterRegion和didExitRegion。@谢谢您的评论。我已经知道了。祝你今天愉快。你在用什么电话?你不应该打StopUpdateLocation。您的应用程序如何知道您当前所在地区的位置?