-5

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

Can anyone help me with solutions or ideas to better achieve this?

Imodeveloper
  • 394
  • 4
  • 13
  • Please ask better question. 1) Your link is dead 2. What have you tried, where does it fail? StackOverflow does not do your work for you – Jan Doggen Apr 04 '14 at 08:57

2 Answers2

7

You can do like that :

 - (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;
    }
HamzaGhazouani
  • 6,464
  • 6
  • 33
  • 40
  • 1
    it connects the annotations, but doesnt draw route – Jasmeet May 21 '14 at 06:41
  • Hello Jeev, sorry, I don't understand what do you mean by : it connects the annotations, but does not draw route, for me the route is the connection between a lot of points (annotations) – HamzaGhazouani Mar 24 '15 at 13:21
  • I mean to say there's a lot difference betwwn connecting the annotations and drawing the route between the annotations. ur code is Connecting the annotations; not drawing the route betwwen them – Jasmeet Mar 25 '15 at 04:53
  • You are correct Jeev, but not completely because we can draw route between two annotations with this code but we must have all coordinates between them (the case of this question), if not, we can use the application Maps to draw itinerary. Best regards – HamzaGhazouani Mar 25 '15 at 08:51
  • drawing the routes betwwn the 2 annotation with the all coordinates between them is not an optimized way. – Jasmeet Mar 25 '15 at 09:48
1

Having this points you can create a polyline containing all the points you want to connect and then add this polyline as an overlay to the map. By map delegate method you can even customise look of this line to your special needs.

I have created lately a rectangle on the Apple's map which is a simpler example of what you want. You can look at the code and probably it will help you. If you need more help please take a look at this

Julian
  • 9,299
  • 5
  • 48
  • 65