简体   繁体   中英

CoreLocation start Monitoring For multi Regions

how can i start monitoring for multi regions by using locationManager startMonitoringForRegion method

for example i have three regions i want to monitor it

CLLocationCoordinate2D centreLoc = {28.965243, 48.149724};
CLLocationDistance regionRadius = 200.00;
CLRegion *grRegion = [[CLRegion alloc] initCircularRegionWithCenter:centreLoc radius:regionRadius identifier:@"grRegion1"];


CLLocationCoordinate2D centreLoc2 = {28.765243, 48.149724};
CLLocationDistance regionRadius2 = 200.00;
CLRegion *grRegion2 = [[CLRegion alloc] initCircularRegionWithCenter:centreLoc2 radius:regionRadius2 identifier:@"grRegion2"];

CLLocationCoordinate2D centreLoc3 = {28.865243, 48.149724};
CLLocationDistance regionRadius3 = 200.00;
CLRegion *grRegion3 = [[CLRegion alloc] initCircularRegionWithCenter:centreLoc3 radius:regionRadius3 identifier:@"grRegion3"];

CLLocationAccuracy acc2=kCLLocationAccuracyBest;
[locationManager startMonitoringForRegion:grRegion2 desiredAccuracy:acc2];

how can start monitor for this three regions ???

You are on the right track.

First, your coordinates should be a double value, you are using a float value.

Second, you need to make separate arrays for Latitude and Longitude, and then take those values at index i.

This should work.

for (int i = 0; i < [AllRegionsArray count]; i++) {
    NSArray *longLati = [allRegionsArray objectAtIndex:i];
    NSMutableArray *latArray = longLati objectAtIndex:0];
    NSMutableArray *longArray = longLati objectAtIndex:1];
    lutiuid = [latArray objectAtIndex:i];
    longtuid = [longArray objectAtIndex:i];

    CLLocationCoordinate2D centreLoc = [CLLocation2DMake([[lutiuid] doubleValue], [[longtuid] doubleValue]);
//iOS 6
    CLRegion *grRegion = [[CLRegion alloc] initWithCenter:centreLoc radius:200 identifier://yourIdentifier, I used the string of the address];
//iOS 7
CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:coordinate radius:radius identifier:identifier];
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startMonitoringForRegion:grRegion];
    NSLog(@"monotoring regions:%@", locationManager.monitoredRegions);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM