我正在用GeoFencing做一个应用程序。我读过这里并开发了一个应用程序。它不会崩溃,但一旦我进入监控区域,它也不会有反应。它确实注销了“开始监视”,但是一旦我选择了我的*.GPX文件,它就没有反应了。这是我的ViewController代码:
@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文件:
<?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区域时它什么也不做?此外,如何创建更合适的标识符?
谢谢!埃里克
发布于 2015-01-01 21:55:50
我相信您忘记将locationManager委托设置为视图控制器:
locationManager.delegate = self;在创建viewDidLoad之后,将其放入locationManager中。
您还应该实现monitoringDidFailForRegion来检测任何错误。调用startMonitoring并不能保证它实际上会启动。它可能会因为各种原因而失败。
https://stackoverflow.com/questions/27732793
复制相似问题