我有一个包含经度和纬度2个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(谷歌地图)中工作正常。