Question

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!

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top