【问题标题】:Route-me: placing a new route on a mapRoute-me:在地图上放置一条新路线
【发布时间】:2015-03-13 21:44:09
【问题描述】:

我有一个使用 Route-me 和静态地图(存储在 sqlite 数据库中的图块)的应用程序。下面的代码正确地将路线添加到地图。但是,我想让应用程序删除显示的路线并添加另一条路线。在代码中,函数在这一行中获取了一组新的路由点(变量 pathNodes)([route createRoute:whichRoute] 方法从 sqlite 数据库中提取数据点 - 这可以正常工作):

pathNodes = [route createRoute:whichRoute];

然后我删除这段代码中的现有层:

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

并在其中添加一个新层:

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

对于创建的第一条路线,这非常有效。 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 用新的子图层重绘自身的问题,但我已经尝试了我能想到或在其他地方发现的所有东西,但没有任何效果。

如何让 mapView 重绘自身。还是有其他我没有看到的问题?

我们将不胜感激所有帮助!

- (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];
}

【问题讨论】:

    标签: ios route-me


    【解决方案1】:

    如果有人还在看这个......

    当路线改变时,我从来没有获得 RouteMe 地图来重绘路线。然而——这是一个很大的问题——iOS 8 和 9 具有制作静态地图以及绘制和重新绘制路线的所有必要功能。这一切都有效。我使用 UIMapKit 在 Swift 中重新编写了整个应用程序,并且效果更好。任何考虑使用 RouteMe 的人 - 我建议您考虑两次、三次和四次这样做。 RouteMe 没有得到维护,只是在一些关键领域存在缺陷。 (我查看了一次源代码以了解到底发生了什么,并发现类中有一些遗留代码,没有人能弄清楚它为什么存在,但如果删除,就会破坏类。)

    UIMapKit - 这就是答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2011-01-11
      • 1970-01-01
      相关资源
      最近更新 更多