This is my code for creating trackable POIs and starting a POI tracking.
This code is placed just before I would calculate a route and start navigation
-(void)createTrackablePOIs
{
// Go through the route array and create POIs out of all added exits and locations
if ([Constants shared].routeArray.count>2){
_trackablePOIs = [[NSMutableArray alloc] init];
for (int i=1; i<[Constants shared].routeArray.count-1; i++) {
if ([[Constants shared].routeArray[i] isKindOfClass:[Exit class]]){
Exit *e = [Constants shared].routeArray[i];
SKTrackablePOI* poi = [[SKTrackablePOI alloc] init];
poi.poiID = e.idExit;
poi.type = 1;
poi.coordinate = CLLocationCoordinate2DMake(e.lat, e.lon);
[self.trackablePOIs addObject:poi];
}else{
RoutePoint* rp = [Constants shared].routeArray[i];
SKTrackablePOI *poi = [[SKTrackablePOI alloc] init];
poi.poiID = rp.pointID;
poi.type = 2;
poi.coordinate = CLLocationCoordinate2DMake(rp.x,rp.y);
[self.trackablePOIs addObject:poi];
}
}
NSLog(@"%d POIs created and added to array",_trackablePOIs.count);
self.poiTracker = [[SKPOITracker alloc] init];
self.poiTracker.dataSource = self;
self.poiTracker.delegate = self;
// Create POI Tracking rules
SKTrackablePOIRule *rule = [SKTrackablePOIRule trackablePOIRule];
rule.routeDistance = 5000;
rule.aerialDistance = 5000;
[_poiTracker setRule:rule forPOIType:1];
// Start POI tracking
[_poiTracker startPOITrackerWithRadius:5000 refreshMargin:0.1 forPOITypes:@[@1,@2]];
}
}
-(NSArray*)poiTracker:(SKPOITracker *)poiTracker trackablePOIsAroundLocation:(CLLocationCoordinate2D)location inRadius:(int)radius withType:(int)poiType
{
return [self.trackablePOIs copy];
}
- (void)poiTracker:(SKPOITracker *)poiTracker didDectectPOIs:(NSArray *)detectedPOIs{
[detectedPOIs enumerateObjectsUsingBlock:^(SKDetectedPOI *detectedPOI, NSUInteger index, BOOL *stop){
NSLog(@"Detected: %@",[detectedPOI description]);
}];
NSLog(@"POI detected");
}
But POI delegate method is never called. No matter how much I played with trackable POI rules.
Also, another question, what exactly does the margin stands for in
[_poiTracker startPOITrackerWithRadius:5000 refreshMargin:0.1 forPOITypes:@[@1,@2]];