objective c - CoreLocation region delegates not called -
i building application location based app, need user coordinates longitude , latitude , worked.
now need know if user enter region predefined using cllocationmanager delegates, override didenterregion nslog statement know if user enter region.
in
-(void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation i call startmonitoringforregion: nothing happen in delegates didenterregion or monitoringdidfailforregion or delegates clregion.
here of code :
-(void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation { loclongittude=newlocation.coordinate.longitude; loclattiude=newlocation.coordinate.latitude; self.regiontimer=[nstimer scheduledtimerwithtimeinterval:3 target:self selector:@selector(monitorregion) userinfo:nil repeats:no]; } -(void)startmonitor:(float)latitude longitude:(float)longitude radius:(float)radius { cllocationcoordinate2d home; home.latitude = latitude; home.longitude = longitude; clregion* region = [[clregion alloc] initcircularregionwithcenter:home radius:radius identifier:@"home"]; if([cllocationmanager regionmonitoringenabled] && [cllocationmanager regionmonitoringavailable]) [locmanager startmonitoringforregion:region desiredaccuracy:kcllocationaccuracybest]; nslog(@"count: %d region aval %d enable %d",[[locmanager monitoredregions]count], [cllocationmanager regionmonitoringavailable],[cllocationmanager regionmonitoringenabled]); for( clregion* region in locmanager.monitoredregions ) nslog( @"%@", region ); } -(void)monitorregion { [self startmonitor:31.971160 longitude:35.832465 radius:10000.0]; } edit : testing done using simulator , simulate location using product-> debug -> simulate location
ok guys works. code above works great problem make didenterregion method called outside region need enter enter make work.
what doing in simulation choose coordinate inside region need enter , problem must outside region.
so here code share you
update : wondering why didexitregion doesn't called when leave region?
as per own experience, looks region monitoring depends on cell change events (why apple designed way? guess increase battery life). so, implementation not ideal.
ideally should work whenever cross boundary, doesn't happens same way on iphone. builtin reminder app, fails nearby location-based reminders.
so in case think cell change event doesn't occur , why didexitregion not called. can double check using startmonitoringsignificantlocationchanges.
Comments
Post a Comment