Reputation: 2027
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!
Upvotes: 0
Views: 539
Reputation: 113747
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.
Upvotes: 2
Reputation: 752
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.
Upvotes: 1