在上篇文章得到了一个polyline数组,例如:
**2016-02-05 16:21:27.928 ****字符串转Polyline数组****[3707:51509] 31.214199,121.535149**
**2016-02-05 16:21:27.929 ****字符串转Polyline数组****[3707:51509] 31.214199,121.535149**
**2016-02-05 16:21:27.929 ****字符串转Polyline数组****[3707:51509] 31.214211,121.535141**
**2016-02-05 16:21:27.929 ****字符串转Polyline数组****[3707:51509] 31.214211,121.535141**
**2016-02-05 16:21:27.929 ****字符串转Polyline数组****[3707:51509] 31.214211,121.535149**
**2016-02-05 16:21:27.929 ****字符串转Polyline数组****[3707:51509] 31.214211,121.535149**
.
.
.
数组总共有389个元素,都是经纬度...
我们把这个数组称为:polylint
地图绘制需要遵循一个代理:<MKMapViewDelegate>
代码如下:
@interface ViewController ()<MKMapViewDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
MKMapView *view = [[MKMapView alloc]initWithFrame:CGRectMake(0 , 0, 375, 667)];
[self.view addSubview:view];
view.delegate = self;
NSArray *polylint = 得到的polyline数组
NSInteger pointCount = polylint.count;
CLLocationCoordinate2D *coordinateArray = (CLLocationCoordinate2D *)malloc(pointCount * sizeof(CLLocationCoordinate2D));
for (int i = 0; i < pointCount; i++)
{
CLLocation *location = [polylint objectAtIndex:i];
coordinateArray[i] = [location coordinate];
NSLog(@"%d",i);
NSLog(@"%f,%f",location.coordinate.latitude,location.coordinate.longitude);
}
MKPolyline *lines = [MKPolyline polylineWithCoordinates:coordinateArray count:pointCount];
[view addOverlay:lines];
MKCoordinateSpan span ={0.03,0.04};
MKCoordinateRegion regon = MKCoordinateRegionMake(coordinateArray[0], span);
[view setRegion:regon animated:YES];
}
//实现画线的代理方法
- (MKPolylineRenderer *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay{
if ([overlay isKindOfClass:[MKPolyline class]]) {
MKPolylineRenderer *line = [[MKPolylineRenderer alloc] initWithOverlay:overlay];
line.strokeColor = [UIColor blackColor];
line.lineWidth = 3.5f;
return line;
}else{
return nil;
}
}
iOS 在地图上绘制行程路线
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 百度地图的文件都没有上传,需要自己导入一下才可以使用.https://github.com/dong1362795...