Route-me: placing a new route on a map

107 views Asked by At

I have an app that uses Route-me with static maps (tiles stored in a sqlite database). The code below correctly adds a route to the map. However, I would like to have the app remove the route shown and add another route. In the code, the function gets a new set of route points (the variable pathNodes) in this line (the [route createRoute:whichRoute] method pulls the datapoints from the sqlite database - this works correctly):

pathNodes = [route createRoute:whichRoute];

Then I remove the existing layer in this code:

    // remove the current layer, which holds the previous route
    if (currentLayer != nil) {
        [mapView.contents.overlay removeSublayer:currentLayer];
    }

and add a new layer in this:

    [mapView.contents.overlay addSublayer:(CALayer *)walkRoute.path];

For the first route created, this works perfectly. But when a new route is chosen, the existing layer gets removed and the new sublayer is added to the mapView, but is never shown.

It appears to me that this is just a matter of getting the mapView to redraw itself with the new sublayer, but I've tried everything i can think of or discover elsewhere, and nothing has worked.

How do I get the mapView to redraw itself. Or is there another problem that I'm not seeing?

All help will be greatly appreciated!

- (void) setRoute {
    NSMutableArray *pathNodes;

    int whichRoute = delegate.selectedRoute;   // delegate.whichRoute will be an integer denoting which route the user has chosen

    Route *route = [[Route alloc] init];// Route stores information about the route, and a way to create the path nodes from a sqlite database

    pathNodes = [route createRoute:whichRoute];
    CMRoute *walkRoute = [[CMRoute alloc] initWithNodes:pathNodes forMap:mapView];

    // remove the current layer, which holds the previous route
    if (currentLayer != nil) {
        [mapView.contents.overlay removeSublayer:currentLayer];
    }

    [mapView.contents.overlay addSublayer:(CALayer *)walkRoute.path];
    currentLayer = (CALayer *)walkRoute.path;

    // set the map's center point, whkch is the startPointlat and long stored in route
    CLLocationCoordinate2D demoCoordinate;
    demoCoordinate.longitude = route.startPoint.longitude;
    demoCoordinate.latitude =  route.startPoint.latitude;

    [mapView setNeedsDisplay];
    [mapView moveToLatLong:demoCoordinate];
}
1

There are 1 answers

0
johnz On

In case anyone is still looking at this...

I never got a RouteMe map to redraw a route when the route changed. However - and this is a big however - iOS 8 and 9 have all the necessary capabilities to do static maps and draw and re-draw routes. And it all works. I re-wrote the entire app in Swift using UIMapKit and it all works much better. Anyone thinking about using RouteMe - I'd recommend thinking twice and three times and four times about doing that. RouteMe is not being maintained and is just plain buggy in some key areas. (I looked at the source code once to see what the heck was going on and found comments that there was some legacy code in the class that no one could figure out why it was there, but if removed, broke the class.)

UIMapKit - that's the answer.