View Full Version : iOS: turn by turn navigation in combination with POITracking

07.12.2014, 16:54

for my pedestrian navigation app I need to generate a route along multiple POI. The route should be shown after the user reached the respective POI (Waypoint). The user shouldn't see the next route before he reaches the POI. 100 meters before every POI a sound file should be played and 20 meters before he reaches the POI the new route to the next POI should be generated and the turn by turn navigation should start navigating.
Here the current route for the use case:

Here my code so far:

NSLog(Poi1Played ? @"Yes" : @"No");
if ([detectedPOI poiID] == 1 && [detectedPOI distance] <= 100 && Poi1Played == 0) {
[self->_audioPlayer stop];
if (_audioPlayer.isPlaying) {
// player is playing
//NSLog(@"player is playing POI2");
} else {
[self playSound:@"Usecase-02-Löwentor"];
Poi1Played = 1;
NSLog(@"POI 1 L÷wentor in 70m");
if ([detectedPOI poiID] == 1 && [detectedPOI distance] <= 20) {
SKRouteSettings* route = [[SKRouteSettings alloc]init];
if (Simulation) {
NSLog(@"Simulation TRUE");
route.startCoordinate=CLLocationCoordinate2DMake(P oi1Lat, Poi1Long);
} else {
NSLog(@"Simulation FALSE");
route.startCoordinate=CLLocationCoordinate2DMake(s elf.locationManager.location.coordinate.latitude, self.locationManager.location.coordinate.longitude );
route.destinationCoordinate=CLLocationCoordinate2D Make(Poi2Lat, Poi2Long);
route.shouldBeRendered = YES; // If NO, the route will not be rendered.
route.requestAdvices = YES;
route.numberOfRoutes = 1;
route.routeMode = SKRoutePedestrian;
route.requestExtendedRoutePointsInfo = YES;
[[SKRoutingService sharedInstance] calculateRoute:route];

NSLog(@"POI 1 L÷wentor in 20m");

SKTrackablePOI *trackablePOI1 = [SKTrackablePOI trackablePOI];
trackablePOI1.poiID = 1;
trackablePOI1.type = kTrackablePOITypeIncident;
trackablePOI1.coordinate = CLLocationCoordinate2DMake(Poi1Lat, Poi1Long);

SKTrackablePOI *trackablePOI2 = [SKTrackablePOI trackablePOI];
trackablePOI2.poiID = 2;
trackablePOI2.type = kTrackablePOITypeIncident;
trackablePOI2.coordinate = CLLocationCoordinate2DMake(Poi2Lat, Poi2Long);

SKTrackablePOI *trackablePOI3 = [SKTrackablePOI trackablePOI];
trackablePOI3.poiID = 3;
trackablePOI3.type = kTrackablePOITypeIncident;
trackablePOI3.coordinate = CLLocationCoordinate2DMake(Poi3Lat, Poi3Long);

SKTrackablePOI *trackablePOI4 = [SKTrackablePOI trackablePOI];
trackablePOI4.poiID = 4;
trackablePOI4.type = kTrackablePOITypeIncident;
trackablePOI4.coordinate = CLLocationCoordinate2DMake(Poi4Lat, Poi4Long);

SKTrackablePOI *trackablePOI5 = [SKTrackablePOI trackablePOI];
trackablePOI5.poiID = 5;
trackablePOI5.type = kTrackablePOITypeIncident;
trackablePOI5.coordinate = CLLocationCoordinate2DMake(Poi5Lat, Poi5Long);
return @[trackablePOI1,trackablePOI2,trackablePOI3,trackabl ePOI4,trackablePOI5];

- (void)routingService:(SKRoutingService *)routingService didFinishRouteCalculationWithInfo:(SKRouteInformat ion*)routeInformation{
NSLog(@"Route is calculated.");

[routingService zoomToRouteWithInsets:UIEdgeInsetsZero]; // zooming to currrent route

//TODO: make this setting global
SKNavigationSettings* navSettings = [SKNavigationSettings navigationSettings];

if (Simulation) {
navSettings.navigationType=SKNavigationTypeSimulat ion;
} else {

[SKRoutingService sharedInstance].mapView.settings.displayMode = SKMapDisplayMode3D;
[[SKRoutingService sharedInstance]startNavigationWithSettings:navSettings];

//saveRoute to cache
// [[SKRoutingService sharedInstance]saveRouteToCache:routeInformation.routeID];

NSArray* advices = [[SKRoutingService sharedInstance] routeAdviceListWithDistanceFormat:SKDistanceFormat Metric];
for (SKRouteAdvice *advice in advices)
// NSLog(@"%@", advice.adviceInstruction);

NSArray* coords = [[SKRoutingService sharedInstance] routeCoordinatesForRouteWithId:routeInformation.ro uteID];
// NSLog(@"Route contains %lu elements",(unsigned long)coords.count);

NSLog(@"New Route is calculated.");
[self startPOITracking];

My problem is that this doesn't work on real streets. In the Xcode Simulator everything works fine.
After the first POI the sound file ist played, the new route is calculated and I see it on the map, but without any turn by turn navigation advices? After that moment only the sound files are played at the specific POI coordinates.

Should I stop the navigation after every POI and clear the route? Should I clear the cache of the route?

Thank you very much,

08.12.2014, 09:53
Hi Ivaylo,

An issue regarding your question has been sent to our development team-we will get back with an answer as soon as we can

08.12.2014, 16:17
Direct from our developers:
"When calculating a new route you have to set it as main in the SKRoutingService.mainRouteId. After that you need to start the navigation again so that it uses the newly calculated route."
Let us know if everything is working as expected.

10.12.2014, 01:56
Setting "[[SKRoutingService sharedInstance] setMainRouteId:routeInformation.routeID];" in my "didFinishRouteCalculationWithInfo" method solved the problem.

Thank you very much,