0

I placed two pins on a map:

- (void)viewDidLoad {
    [super viewDidLoad];

    CLLocationCoordinate2D cord1 = {.latitude = 44.508473, .longitude =  11.375828};
    CLLocationCoordinate2D cord2 = {.latitude = 44.508871, .longitude =  11.375854};

    [self.mapView setRegion:MKCoordinateRegionMake(cord1, MKCoordinateSpanMake(.005, .005)) animated:YES];
    [self.mapView setRegion:MKCoordinateRegionMake(cord2, MKCoordinateSpanMake(.005, .005)) animated:YES];


    AddressAnnotation * annotazione = [[AddressAnnotation alloc] init];
    AddressAnnotation * annotazione2 = [[AddressAnnotation alloc] init];

    [annotazione setCoordinate:cord1];
    [annotazione2 setCoordinate:cord2];

    [self.mapView addAnnotation:annotazione];
    [self.mapView addAnnotation:annotazione2];
}

Is there a way to connect pins with a line? Thank you!

nevan king
  • 112,709
  • 45
  • 203
  • 241
Matte.Car
  • 2,007
  • 4
  • 23
  • 41
  • [Google "CoreGraphics iOS draw line".](http://google.com/search?q=CoreGraphics+iOS+draw+line) –  Mar 28 '13 at 18:29
  • I saw it but...isn't there an easier way? I've just to connect pins, no route, google or other complications... – Matte.Car Mar 28 '13 at 19:09
  • I don't think `CGContextAddLines(UIGraphicsGetCurrentContext(), twoPoints, 2);` is particularly difficult... –  Mar 28 '13 at 19:11

2 Answers2

2

MKPolyline has the method polylineWithCoordinates:count:, which takes a number of coordinates. You already have the two coordinates you need (cord1 and cord2) to create a polyline. Add the overlay to your map and implement mapView:viewForOverlay: to return an overlay view.

nevan king
  • 112,709
  • 45
  • 203
  • 241
1

In iOS 4.x, Apple added support for map overlays. It might help to read a little bit more about the MKPolyline & MKPolylineView classes and the mapView:viewForOverlay: method defined in the MKMapViewDelegate protocol. All available in the Map Kit Framework Reference.

Shashikanth
  • 752
  • 5
  • 13