kh1090 kh1090 - 6 months ago 25
Objective-C Question

Annotate 2 points on map using addresses inside labels. - Objective C

enter image description here

I would like to drop a pin on the map showing the location of each address. The labels are pre-filled with data, so I am assuming the annotation code will need to go in the


To avoid any confusion and to help clarify a correct answer, the labels are named


Reapeat the same process for lblRightAddress also.

 // NSString *location = lblLeftAddress.text; I hust checked with your address it worked.
 NSString *location = @"296 Broadway Blvd Santa Monica CA 90016";
        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;
                             region.span.longitudeDelta /= 8.0;
                             region.span.latitudeDelta /= 8.0;

                             [self.mapView setRegion:region animated:YES];
                             [self.mapView addAnnotation:placemark];