简体   繁体   English

我的路线:在地图上放置新路线

[英]Route-me: placing a new route on a map

I have an app that uses Route-me with static maps (tiles stored in a sqlite database). 我有一个将Route-me与静态地图(切片存储在sqlite数据库中)结合使用的应用。 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]方法从sqlite数据库中提取数据点-可以正常工作):

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. 但是,当选择新路线时,现有图层将被删除,新的子图层将添加到mapView中,但是从不显示。

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. 在我看来,这只是让mapView用新的子层重新绘制自身的问题,但是我已经尝试了我可以想到或在其他地方发现的所有内容,但没有任何效果。

How do I get the mapView to redraw itself. 如何获取mapView重绘自身。 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];
}

In case anyone is still looking at this... 万一有人还在看这个...

I never got a RouteMe map to redraw a route when the route changed. 路线更改时,我从未得到过RouteMe地图来重绘路线。 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. 但是-这是一个很大的问题-iOS 8和9具有执行静态地图以及绘制和重新绘制路线的所有必要功能。 And it all works. 而且一切正常。 I re-wrote the entire app in Swift using UIMapKit and it all works much better. 我使用UIMapKit在Swift中重新编写了整个应用程序,并且效果都更好。 Anyone thinking about using RouteMe - I'd recommend thinking twice and three times and four times about doing that. 任何想使用RouteMe的人-建议您考虑两次,三遍和四遍。 RouteMe is not being maintained and is just plain buggy in some key areas. RouteMe并未得到维护,在某些关键领域只是普通的越野车。 (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. UIMapKit-就是答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM