首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在iOS 6地图上绘制多条路径

如何在iOS 6地图上绘制多条路径
EN

Stack Overflow用户
提问于 2012-11-22 09:37:04
回答 1查看 1.7K关注 0票数 0

可能重复: Multiple MKPolyline on MKMapView iOS6

我有两个csv文件,包含纬度和经度。我想在iOS 6地图上画两条线或路线。我该怎么做??

我已经尝试了下面的代码来绘制单一的折线。

代码语言:javascript
复制
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"route" ofType:@"csv"];
NSString* fileContents = [NSString stringWithContentsOfFile:filePath];
NSArray* pointStrings = [fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

NSMutableArray* points = [[NSMutableArray alloc] initWithCapacity:pointStrings.count];

for(int idx = 0; idx < pointStrings.count; idx++)
{
    // break the string down even further to latitude and longitude fields.
    NSString* currentPointString = [pointStrings objectAtIndex:idx];
    NSArray* latLonArr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];

    CLLocationDegrees latitude  = [[latLonArr objectAtIndex:0] doubleValue];
    CLLocationDegrees longitude = [[latLonArr objectAtIndex:1] doubleValue];

    CLLocation* currentLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
    [points addObject:currentLocation];
}

// create our route layer view, and initialize it with the map on which it will be rendered.
_routeView = [[CSMapRouteLayerView alloc] initWithRoute:points mapView:mapView];

但这段代码的问题是,我不能滚动地图,也可以双击放大无法工作(基本上是地图冻结)。尽管它在Xcode 4.3中运行良好(使用谷歌地图)。

EN

回答 1

Stack Overflow用户

发布于 2012-11-22 10:23:09

不要使用CSMapRouteLayerView,而是使用mapview本身。您可以轻松地在mapView上绘制自定义路径。

参见MKMapKit引用:index.html

创建具有以下类的覆盖:

MKOverlayPathView

MKPolylineViewMKPolyline表示行。

(如果您想要MKPolygonView和‘`MKPolygon for多边形。)

若要在mapView中使用这些类,请使用以下方法/委托:

MKMapView :向地图添加覆盖

– addOverlay:

MKMapViewDelegate:管理覆盖视图

– mapView:viewForOverlay:

– mapView:didAddOverlayViews:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13509640

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档