首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多地域CoreLocation start监控

多地域CoreLocation start监控
EN

Stack Overflow用户
提问于 2013-06-11 17:47:41
回答 1查看 2.4K关注 0票数 2

如何使用locationManager startMonitoringForRegion方式开始多地域监控?

例如,我有三个区域想要监视它

代码语言:javascript
复制
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];

如何启动这三个区域的监控?

EN

回答 1

Stack Overflow用户

发布于 2013-09-26 21:59:27

你在正确的轨道上。

首先,您的坐标应该是双精度值,您使用的是浮点值。

其次,您需要为纬度和经度创建单独的数组,然后在索引i处获取这些值。

这应该是可行的。

代码语言:javascript
复制
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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17041167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档