首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GeoFencing不起作用

GeoFencing不起作用
EN

Stack Overflow用户
提问于 2015-01-01 17:03:14
回答 1查看 482关注 0票数 0

我正在用GeoFencing做一个应用程序。我读过这里并开发了一个应用程序。它不会崩溃,但一旦我进入监控区域,它也不会有反应。它确实注销了“开始监视”,但是一旦我选择了我的*.GPX文件,它就没有反应了。这是我的ViewController代码:

代码语言:javascript
复制
@interface myViewController () {
CLLocationManager *locationManager;
}

@end

@implementation RegisterViewController

@synthesize GeoFences;

- (void)viewDidLoad {
[super viewDidLoad];

// Initalize locationManager
locationManager = [[CLLocationManager alloc] init];
}

- (IBAction)getLocation:(id)sender {
// Start monitoring
// Create a home NSDictionary
NSDictionary *myDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"23123124arevar", @"title", @"00.0", @"latitude", @"00.0", @"longitude", @"100", @"radius", nil];
NSMutableArray *regions = [[NSMutableArray alloc] init];
CLRegion *region = [self mapDictionaryToRegion:myDictionary];
[regions insertObject:region atIndex:0];
NSLog(@"Count: %lu", [regions count]);
[self startMonitoringRegions:regions];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (CLRegion*)mapDictionaryToRegion:(NSDictionary*)dictionary
{
NSString *title = [dictionary valueForKey:@"title"];

CLLocationDegrees latitude = [[dictionary valueForKey:@"latitude"] doubleValue];
CLLocationDegrees longitude =[[dictionary valueForKey:@"longitude"] doubleValue];
CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(latitude, longitude);

CLLocationDistance regionRadius = [[dictionary valueForKey:@"radius"] doubleValue];

return [[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate
                                               radius:regionRadius
                                           identifier:title];
}

-(void)startMonitoringRegions:(NSMutableArray *)array {
for (CLRegion *GeoFence in array)
{
    NSLog(@"Started monitoring");
    [locationManager startMonitoringForRegion:GeoFence];
}
}

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog(@"Exited Region - %@", region.identifier);
// post a notification
}

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
NSLog(@"Exited Region - %@", region.identifier);
// post a notification
}

@end

这是我的*.GPX文件:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<gpx
xmlns="http://www.topografix.com/GPX/1/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
version="1.1" 
creator="gpx-poi.com">
<wpt lat="00.0" lon="00.0">
<time>2015-01-01T14:45:02Z</time>
</wpt>
</gpx>

我用00.0.替换了我的实际坐标

有人能帮我解决这个问题吗?为什么当我进入我的*.GPX区域时它什么也不做?此外,如何创建更合适的标识符?

谢谢!埃里克

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-01 21:55:50

我相信您忘记将locationManager委托设置为视图控制器:

代码语言:javascript
复制
    locationManager.delegate = self;

在创建viewDidLoad之后,将其放入locationManager中。

您还应该实现monitoringDidFailForRegion来检测任何错误。调用startMonitoring并不能保证它实际上会启动。它可能会因为各种原因而失败。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27732793

复制
相关文章

相似问题

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