kh1090 kh1090 - 1 year ago 99
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

Answer Source

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];


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download