我有两个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中运行良好(使用谷歌地图)。
发布于 2012-11-22 10:23:09
不要使用CSMapRouteLayerView,而是使用mapview本身。您可以轻松地在mapView上绘制自定义路径。
参见MKMapKit引用:index.html
创建具有以下类的覆盖:
MKOverlayPathView或
MKPolylineView和MKPolyline表示行。
(如果您想要MKPolygonView和‘`MKPolygon for多边形。)
若要在mapView中使用这些类,请使用以下方法/委托:
MKMapView :向地图添加覆盖
– addOverlay:
MKMapViewDelegate:管理覆盖视图
– mapView:viewForOverlay:
– mapView:didAddOverlayViews:
https://stackoverflow.com/questions/13509640
复制相似问题