Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 路线me:在地图上放置新路线_Ios_Route Me - Fatal编程技术网

Ios 路线me:在地图上放置新路线

Ios 路线me:在地图上放置新路线,ios,route-me,Ios,Route Me,我有一个应用程序使用Route me和静态地图(存储在sqlite数据库中的分幅)。下面的代码正确地将路线添加到地图中。但是,我想让应用程序删除显示的路线并添加另一条路线。在代码中,该函数在此行中获取一组新的路由点(变量pathNodes)([route createRoute:whichRoute]方法从sqlite数据库中提取数据点-这可以正常工作): 然后,我删除此代码中的现有层: // remove the current layer, which holds the previ

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

然后,我删除此代码中的现有层:

    // remove the current layer, which holds the previous route
    if (currentLayer != nil) {
        [mapView.contents.overlay removeSublayer:currentLayer];
    }
并在此中添加一个新层:

    [mapView.contents.overlay addSublayer:(CALayer *)walkRoute.path];
对于创建的第一条管线,此操作非常有效。但是,如果选择了新的路线,现有图层将被删除,新的子图层将添加到地图视图中,但从未显示

在我看来,这只是一个让地图视图用新的子层重新绘制自己的问题,但我已经尝试了所有我能想到或在其他地方发现的东西,但没有任何效果

如何使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 8和iOS 9具备所有必要的功能,可以进行静态映射、绘制和重新绘制路由。这一切都很有效。我用UIMapKit在Swift中重新编写了整个应用程序,效果更好。任何想使用RouteMe的人——我建议你考虑两次、三次、四次。RouteMe并没有得到维护,只是在一些关键区域有一辆普通的马车。(我看了一次源代码,看看到底发生了什么,发现有评论说类中有一些遗留代码,没有人能弄清楚它为什么存在,但如果删除,就会破坏类。)

这就是答案

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