PDA

View Full Version : Route rendering problems in iOS



algrid
27.11.2014, 13:25
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:

1715

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

1716

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

(void)routingService:(SKRoutingService *)routingService didFinishRouteCalculationWithInfo:(SKRouteInformat ion*)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):



- (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:(SKRouteInformat ion*)routeInformation{
NSLog(@"Route is calculated.");
[routingService zoomToRouteWithInsets:UIEdgeInsetsZero];
}

- (void)routingServiceDidFailRouteCalculation:(SKRou tingService *)routingService{
NSLog(@"Route calculation failed.");
}


I'd really appreciate any help with this.

Adela_Silvia
28.11.2014, 15:19
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.

algrid
28.11.2014, 16:22
Hi Adela,

Many thanks for your explanation and hints.
Adding

[[SKRoutingService sharedInstance] clearCurrentRoutes];
in viewDidDisappear really fixed the issue with route rendering!

guidove
22.04.2015, 18:15
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).
2040
However after this:

@IBAction func tappedCenterOnRouteAndCurrentLocationButton(sender : AnyObject) {
mapView.animateToZoomLevel(trackAndCurLocationRegi on.zoomLevel)
mapView.animateToLocation(trackAndCurLocationRegio n.center, withDuration: 0.25)
}

followed by this:

@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.
2041

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.

SKRoutingService.sharedInstance().clearCurrentRout es()
SKRoutingService.sharedInstance().loadRouteFromCac he(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).


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 (http://forum.skobbler.com/showthread.php/6964-Get-notified-when-map-has-been-loaded) to calculate the route.

Any help or info would be welcome. Thanks in advance for your help.

Adela_Silvia
08.05.2015, 17:33
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)

Adela_Silvia
05.06.2015, 15:54
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.