Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8751117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:59:07+00:00 2026-06-13T12:59:07+00:00

I am able to place a single annotation on MKMapView using the following code:

  • 0

I am able to place a single annotation on MKMapView using the following code:

[self.geocoder geocodeAddressString:value completionHandler:^(NSArray *placemarks, NSError *error) {
                if ([placemarks count] > i) {
                    CLPlacemark *placemark = [placemarks objectAtIndex:0];
                    location = placemark.location;
                    coordinate = location.coordinate;
                    coordinate.latitude = location.coordinate.latitude;
                    coordinate.longitude = location.coordinate.longitude;


                    MKCoordinateRegion newRegion;
                    newRegion.center.latitude = coordinate.latitude;
                    newRegion.center.longitude = coordinate.longitude;
                    newRegion.span.latitudeDelta = 0.029321;
                    newRegion.span.longitudeDelta = 0.034589;
                    //newRegion.span.latitudeDelta = 0.579321;
                    //newRegion.span.longitudeDelta = 1.234589;
                    MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
                    [annotation setCoordinate:coordinate];
                    //  AppDelegate *dataCenter = (AppDelegate *) [[UIApplication sharedApplication] delegate];
                    NSArray *web = [detail valueForKeyPath:@"Name"];
                    NSString *value = [web objectAtIndex:0];
                    [annotation setTitle:value];


                }
            }];

Were value is the address that I pass.

But now, I want to use the same code (probably in a) for loop so, that I can geocode all the values of address obtained in an array from mysql database. Please guide me how to do
so

UPDATE:

I get the values from my sql database in an array.

 $count = [web count];

    for (int i=0; i< count ; i++) {
            NSString *value = [web objectAtIndex:i];
            [self.geocoder geocodeAddressString:value completionHandler:^(NSArray *placemarks, NSError *error) {
                if ([placemarks count] > i) {
                    CLPlacemark *placemark = [placemarks objectAtIndex:0];
                    location = placemark.location;
                    coordinate = location.coordinate;
                    coordinate.latitude = location.coordinate.latitude;
                    coordinate.longitude = location.coordinate.longitude;


                    MKCoordinateRegion newRegion;
                    newRegion.center.latitude = coordinate.latitude;
                    newRegion.center.longitude = coordinate.longitude;
                    newRegion.span.latitudeDelta = 0.029321;
                    newRegion.span.longitudeDelta = 0.034589;
                    //newRegion.span.latitudeDelta = 0.579321;
                    //newRegion.span.longitudeDelta = 1.234589;
                    MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
                    [annotation setCoordinate:coordinate];
                    //  AppDelegate *dataCenter = (AppDelegate *) [[UIApplication sharedApplication] delegate];
                    NSArray *web = [detail valueForKeyPath:@"Name"];
                    NSString *value = [web objectAtIndex:0];
                    [annotation setTitle:value];


                }
            }];
}

COMPLETE METHOD::

-(void) showSourceDest {
if (!self.geocoder) {
    self.geocoder = [[CLGeocoder alloc] init];
}
AppDelegate *dataCenter = (AppDelegate *) [[UIApplication sharedApplication] delegate];
NSLog(@"Opening: %@", dataCenter.data);
[self setTitle:@"Map"];

NSString *address = dataCenter.data;

[self.geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
    if ([placemarks count] > 0) {
        CLPlacemark *placemark = [placemarks objectAtIndex:0];
        location = placemark.location;
        coordinate = location.coordinate;
        coordinate.latitude = location.coordinate.latitude;
        coordinate.longitude = location.coordinate.longitude;

        //for first co-ordinate :: SOURCE
        MKCoordinateRegion newRegion;
        newRegion.center.latitude = coordinate.latitude;
        newRegion.center.longitude = coordinate.longitude;
        newRegion.span.latitudeDelta = 0.029321;
        newRegion.span.longitudeDelta = 0.034589;

        MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
        [annotation setCoordinate:coordinate];
         AppDelegate *dataCenter = (AppDelegate *) [[UIApplication sharedApplication] delegate];
        [annotation setTitle:dataCenter.hotelname];
        [self.mapView addAnnotation:annotation];

        //second annotation for SDSU :: DESTINATION
       location2 = placemark.location;
        coordinate2 = location.coordinate;
        coordinate2.latitude = 32.774774;
        coordinate2.longitude = -117.072262;

        MKCoordinateRegion collRegion;
        collRegion.center.latitude = 32.774774;
        collRegion.center.longitude = -117.072262;
        collRegion.span.latitudeDelta = 0.029321;
        collRegion.span.longitudeDelta = 0.044589;
        MKPointAnnotation *annotation2 = [[MKPointAnnotation alloc] init];
        [annotation2 setCoordinate:coordinate2];

        [annotation2 setTitle:@"SDSU"];
        [self.mapView addAnnotation:annotation2];

        NSArray *web = [detail valueForKeyPath:@"Address"];
        NSLog(@"NO OF VALUES:: %@", web);
        int count = [web count];

        //Other place of interest nearby
        for (int i = 0; i < count; i++)
        {
            NSString *value = [web objectAtIndex:i];
            [self.geocoder geocodeAddressString:value completionHandler:^(NSArray *placemarks, NSError *error) {
                if ([placemarks count] > 0) {
                    CLPlacemark *placemark = [placemarks objectAtIndex:0];
                    location = placemark.location;
                    coordinate = location.coordinate;
                    coordinate.latitude = location.coordinate.latitude;
                    coordinate.longitude = location.coordinate.longitude;


                    MKCoordinateRegion newRegion;
                    newRegion.center.latitude = coordinate.latitude;
                    newRegion.center.longitude = coordinate.longitude;
                    newRegion.span.latitudeDelta = 0.029321;
                    newRegion.span.longitudeDelta = 0.034589;
                    MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
                    [annotation setCoordinate:coordinate];
                    [annotation setTitle:value];
                    [self.mapView addAnnotation:annotation];
                    [self.mapView setRegion:collRegion animated:YES];

                }
            }];
        }
    }
 }];

}

The block inside the for loop executes only once! 🙁
Not sure, but is it because the block variable is not getting updated?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:59:08+00:00Added an answer on June 13, 2026 at 12:59 pm

    Problem solved:

    MKCoordinateRegion newRegion;
    newRegion.center.latitude = [[[detail valueForKey:@"Latitude"] objectAtIndex:i] doubleValue];
    newRegion.center.longitude = [[[detail valueForKey:@"Longitude"] objectAtIndex:i] doubleValue];
    

    where :

    NSDictionary *detail;
    

    So basically, [ doubleValue];

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to be able to place the error message when using jQuery validation
I am not able to place a div at the top center of a
Not able to store all binary data values into sqlite3 table using QT. For
I need to be able to flush a single entity to the DB during
I am able to place multiple charts on a chart sheet by creating an
This might be a silly question, but i am stuck at a single place
I previously inquired about synchronizing two threads without using pthread_join and I was able
I want to be able to detect a single click or a double click
I have a situation like this I'm using a single activity but with different
I'm able to compile code that includes this: OperationDelegate myOpDelegate; static OperatorDefinition[] definitions ={

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.