Results 1 to 6 of 6

Thread: Route rendering problems in iOS

  1. #1
    Neuer skobbler
    Join Date
    27.11.2014
    Posts
    5

    Route rendering problems in iOS

    Hi,

    I have a problem with route drawing in my iOS app. The scenario is the following:
    I have a ViewController with a button, on tap of this button another ViewController is opened - it contains SKMapView with two point marked by annotations and a route between them.

    When the ViewController with map is opened first time everything is fine:

    iOS Simulator Screen Shot Nov 27, 2014, 12.56.04 PM.jpg

    But when I tap back and open the same screen second time the last part of the route is not visible:

    iOS Simulator Screen Shot Nov 27, 2014, 12.55.52 PM.jpg

    If I start to zoom in/out then the whole route appears and later I have no problems.

    Some other strange things:

    1. For some reason
    Code:
    (void)routingService:(SKRoutingService *)routingService didFinishRouteCalculationWithInfo:(SKRouteInformation*)routeInformation
    is called twice (as far as I can see this depends on the starting point of the route - for some starting points it's called only once)

    2. On first app start after install the route is not calculated at all (didFinishRouteCalculationWithInfo is not called, routingServiceDidFailRouteCalculation also isn't called). I have to restart the app or several times open/close the screen with the map in order to get it working.


    Related source code fragment (my ViewController with SKMapView):

    Code:
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        point1 = CLLocationCoordinate2DMake(46.0, 14.4);
        point2 = CLLocationCoordinate2DMake(46.7999, 16.096001);
        
        SKMapView *mapView = [[SKMapView alloc] initWithFrame:CGRectMake(0.0f, 0.0f,  CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];
    
        SKCoordinateRegion region;
        region.center = point1;
        region.zoomLevel = 7.0;
        [mapView setVisibleRegion:region];
        
    
        //Add annotations
        SKAnnotation *annotation = [SKAnnotation annotation];
        annotation.identifier = 10;
        annotation.annotationType = SKAnnotationTypeGreen;
        annotation.location = point1;
        SKAnimationSettings *animationSettings = [SKAnimationSettings animationSettings];
        [mapView addAnnotation:annotation withAnimationSettings:animationSettings];
        
        annotation = [SKAnnotation annotation];
        annotation.identifier = 11;
        annotation.annotationType = SKAnnotationTypeBlue;
        annotation.location = point2;
        animationSettings = [SKAnimationSettings animationSettings];
        [mapView addAnnotation:annotation withAnimationSettings:animationSettings];
        
        
        //Add route
        [SKRoutingService sharedInstance].routingDelegate = self;
        [SKRoutingService sharedInstance].mapView = mapView;
        SKRouteSettings* route = [[SKRouteSettings alloc]init];
        route.startCoordinate = point1;
        route.destinationCoordinate = point2;
        route.shouldBeRendered = YES;
        route.routeMode = SKRouteCarFastest;
        route.numberOfRoutes = 1;
        route.avoidHighways = YES;
        [[SKRoutingService sharedInstance] calculateRoute:route];
        
        mapView.delegate = self;
        [self.view addSubview:mapView];
    
    }
    
    - (void)routingService:(SKRoutingService *)routingService didFinishRouteCalculationWithInfo:(SKRouteInformation*)routeInformation{
        NSLog(@"Route is calculated.");
        [routingService zoomToRouteWithInsets:UIEdgeInsetsZero];
    }
    
    - (void)routingServiceDidFailRouteCalculation:(SKRoutingService *)routingService{
        NSLog(@"Route calculation failed.");
    }
    I'd really appreciate any help with this.
    Last edited by algrid; 27.11.2014 at 14:00.

  2. #2
    Oberskobbler
    Join Date
    22.07.2014
    Posts
    399
    Hi Algrid,

    An answer directly from our dev team:

    "A. The didFinishRouteCalculationWithInfo: method is called twice but it's actually the same route (if you look at the routeID it's the same). The reason is that if you want to make a navigation and it's a long route the route calculation could take longer. The first time didFinishRouteCalculationWithInfo: is called the route may not be completely calculated (just a few tens of kilometers at the beginning) but you can start navigating on it. To check if the route is completely finished you should just check if routeInformation.corridorIsDownloaded is YES.
    B. Route calculation fail at first startup is because the tiles are not loaded yet (becuase of slow internet connection). The fail callback has been changed to routingService:didFailWithErrorCode:. The old one has been removed. Please see SKRoutingDelegate.

    As for the route rendering problem, we will investigate it for the next release. You could solve the problem by clearing the route in your viewWillDisappear: and recalculating it when showing the viewcontroller. If you don't want to recalculate it you could just cache on viewWillDissappear: using [[SKRoutingService sharedInstance] saveRouteToCache:routeID] and load it in viewWillAppear: using [[SKRoutingService sharedInstance] loadRouteFromCache:routeID];"

    Please let us know if we can help you further.

  3. #3
    Neuer skobbler
    Join Date
    27.11.2014
    Posts
    5
    Hi Adela,

    Many thanks for your explanation and hints.
    Adding
    Code:
    [[SKRoutingService sharedInstance] clearCurrentRoutes];
    in viewDidDisappear really fixed the issue with route rendering!

  4. #4
    Erfahrener skobbler
    Join Date
    11.02.2015
    Posts
    123
    Hi Adela,

    Was wondering if you found something more on this that could resolve it, because I seem to have a similar problem with Route Rendering and the suggested workarround doesn't work for me.
    This is my situation:

    When I calculate the route it is fully rendered as shown in screenshot (the red line is the calculated route).
    2015-04-22 10.56.11.jpg
    However after this:
    Code:
    @IBAction func tappedCenterOnRouteAndCurrentLocationButton(sender: AnyObject) {
        mapView.animateToZoomLevel(trackAndCurLocationRegion.zoomLevel)
        mapView.animateToLocation(trackAndCurLocationRegion.center, withDuration: 0.25)
    }
    followed by this:
    Code:
    @IBAction func tappedCenterOnRouteButton(sender: AnyObject) {
        mapView.animateToZoomLevel(trackRegion.zoomLevel)
        mapView.animateToLocation(trackRegion.center, withDuration: 0.25)
    }
    The route is displayed only partially, like in below screenshot.
    2015-04-22 10.56.22.jpg

    Then, when I pinch to zoom-in, at a certain zoom level the route appears fully again and it stays that way even when zooming out afterwards.

    As suggested above I tried caching the route and then adding below code to the 2nd function, but that didn't solve the issue for me.
    Code:
    SKRoutingService.sharedInstance().clearCurrentRoutes()
    SKRoutingService.sharedInstance().loadRouteFromCache(calculatedRouteID)
    What's strange is that is does not happen for all the routes I calculate. So, it seems a bit random. Below are the routepoints of the route shown in the screenshots. It's a route with 10 via points. Notice that start and end coordinates are the same (could that be a cause perhaps??). I can send the GPX file to you if you want (attaching or pasting it is not possible with the forum editor).

    Code:
    lat="43.86965274810791" lon="-103.58266353607178"
    lat="43.936166586354375" lon="-103.57242906466126"
    lat="44.03045654296875" lon="-103.49678993225098"
    lat="44.358254252001643" lon="-103.7415322009474"
    lat="44.351923651993275" lon="-103.76827273517847"
    lat="44.299249593168497" lon="-103.86738806962967"
    lat="44.473837679252028" lon="-103.84812955744565"
    lat="44.299249593168497" lon="-103.86738806962967"
    lat="43.788237813860178" lon="-104.07724460586905"
    lat="43.766312599182129" lon="-103.600172996521"
    lat="43.839450655505061" lon="-103.63835164345801"
    lat="43.86965274810791" lon="-103.58266353607178"
    I use the code mentioned in another forum question of mine to calculate the route.

    Any help or info would be welcome. Thanks in advance for your help.
    Last edited by guidove; 22.04.2015 at 18:21.

  5. #5
    Oberskobbler
    Join Date
    22.07.2014
    Posts
    399
    I've forwarded to our developers. I'll let you know when I have an update (please note it might take a while - we're planning the next release for these weeks)

  6. #6
    Oberskobbler
    Join Date
    22.07.2014
    Posts
    399
    Hi Guidove,

    Indeed it's an issue on our core side. We'll try to fix it for the next release, but unfortunately we can not suggest any workaround for the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •