iOS地图在多个点(地理位置)之间绘制路线(线) [英] iOS Maps draw route (line) between several points (geopoints)

查看:241
本文介绍了iOS地图在多个点(地理位置)之间绘制路线(线)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须解决一个问题。
我在服务器上存储了很多坐标,它们代表了一个课程,我必须在地图上绘制课程,必须支持iOS6和iOS7

I have to solve a problem. I have stored on the server a lot of coordinates, they represent a course, and I have to draw the course on the map, must support iOS6 and iOS7

所以,应该能够画出这样的东西

So, should be able to draw something like this

任何人都可以帮我解决方案或想法以更好地实现这一目标吗?

推荐答案

你可以这样做:

 - (void)viewDidLoad {
        [super viewDidLoad];

        // center map
        CLLocationCoordinate2D startCoord = CLLocationCoordinate2DMake(47.081012, 2.398781);
        MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:MKCoordinateRegionMakeWithDistance(startCoord, 3000000, 3000000)];
        [self.mapView setRegion:adjustedRegion animated:YES];

        [self showLines];
    }

    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
    }

    - (void)showLines {
        CLLocationCoordinate2D *pointsCoordinate = (CLLocationCoordinate2D *)malloc(sizeof(CLLocationCoordinate2D) * 3);
        pointsCoordinate[0] = CLLocationCoordinate2DMake(48.856614, 2.352221);
        pointsCoordinate[1] = CLLocationCoordinate2DMake(45.764043, 4.835658);
        pointsCoordinate[2] = CLLocationCoordinate2DMake(43.296482, 5.369779);


        MKPolyline *polyline = [MKPolyline polylineWithCoordinates:pointsCoordinate count:3];
        free(pointsCoordinate);

        [self.mapView addOverlay:polyline];
    }


    - (MKPolylineRenderer *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay{

        // create a polylineView using polyline overlay object
        MKPolylineRenderer *polylineView = [[MKPolylineRenderer alloc] initWithPolyline:overlay];

// Custom polylineView
        polylineView.strokeColor =  [UIColor orangeColor];   
        polylineView.lineWidth = 2.0;
        polylineView.alpha = 0.5;

        return polylineView;
    }

这篇关于iOS地图在多个点(地理位置)之间绘制路线(线)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆