繁体   English   中英

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

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

我有一个将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];

对于创建的第一条路线,这非常理想。 但是,当选择新路线时,现有图层将被删除,新的子图层将添加到mapView中,但是从不显示。

在我看来,这只是让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];
}

万一有人还在看这个...

路线更改时,我从未得到过RouteMe地图来重绘路线。 但是-这是一个很大的问题-iOS 8和9具有执行静态地图以及绘制和重新绘制路线的所有必要功能。 而且一切正常。 我使用UIMapKit在Swift中重新编写了整个应用程序,并且效果都更好。 任何想使用RouteMe的人-建议您考虑两次,三遍和四遍。 RouteMe并未得到维护,在某些关键领域只是普通的越野车。 (我查看了源代码一次,以查看到底发生了什么,并发现注释表明该类中有一些旧代码,没有人能弄清楚它为什么在那里,但是如果删除了,则会破坏该类。)

UIMapKit-就是答案。

暂无
暂无

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

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