【问题标题】:How to draw multiple routes on iOS 6 maps [duplicate]如何在 iOS 6 地图上绘制多条路线 [重复]
【发布时间】:2012-11-22 09:37:04
【问题描述】:

可能重复:
Multiple MKPolyline on MKMapView iOS6

我有两个包含纬度和经度的 csv 文件。我想在 iOS 6 地图上绘制两条折线或路线。我怎样才能做到这一点??

我已尝试使用以下代码来绘制单条折线。

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(使用谷歌地图)中运行良好。

【问题讨论】:

    标签: iphone polyline ios6-maps


    【解决方案1】:

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

    参见 MKMapKit 参考: http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MapKit_Framework_Reference/_index.html

    使用以下类创建叠加层:
    MKOverlayPathView 或
    MKPolylineView 和 MKPolyline 用于线条。
    (如果你想要 MKPolygonView 和 `MKPolygon 用于多边形。)

    要将这些类与 mapView 一起使用,请使用以下方法/委托:

    MKMapView:向地图添加叠加层
    – addOverlay:

    MKMapViewDelegate:管理叠加视图
    – mapView:viewForOverlay:
    – mapView:didAddOverlayViews:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多