I would like to draw a line between two annotation pins based on address strings. The address labels are pre-filled with data from the user and can be any location in the united states. I already have an annotation on each address, I am just unsure of what to put for the coordinate array (lat, long) in order to draw a line between these two points. I have attached 2 screenshots to help clarify and show the errors I am receiving.
Here is how I am annotating each address:
NSString *location = [(UILabel *)[[self view] viewWithTag:1]text];;
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:location
completionHandler:^(NSArray* placemarks, NSError* error){
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
MKCoordinateRegion region = self.mapView.region;
[self.mapView setRegion:region animated:NO];
[self.mapView addAnnotation:placemark];
}
}
];
NSString *location2 = [(UILabel *)[[self view] viewWithTag:6]text];;
CLGeocoder *geocoder2 = [[CLGeocoder alloc] init];
[geocoder2 geocodeAddressString:location2
completionHandler:^(NSArray* placemarks, NSError* error){
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
MKCoordinateRegion region = self.mapView.region;
[self.mapView setRegion:region animated:NO];
[self.mapView addAnnotation:placemark];
}
}
];
Here is the error where I do not know what to put for latitude and longitude in the coordinate array:
CLLocationCoordinate2D coordinateArray[2];
coordinateArray[0] = CLLocationCoordinate2DMake(lat1, lon1);<- NEED HELP HERE
coordinateArray[2] = CLLocationCoordinate2DMake(lat2, lon2);<- NEED HELP HERE
self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:2];
[self.mapView setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible
[self.mapView addOverlay:self.routeLine];