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 8480407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:17:12+00:00 2026-06-10T19:17:12+00:00

I have only a couple of months experience on Objective-C. I have a code

  • 0

I have only a couple of months experience on Objective-C.

I have a code to search a list of customer address, then show the annotation of these addresses. As the customers cover many regions, I would like to make map view’s center and span adapt to the results.

Therefore, I planed to record all searched place marks and calculate an average latitude and longitude. Below is my code

self.mapView.mapType = MKMapTypeStandard; 
for (Customer *customer in customers) {
    CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
    NSString *customerAddress = [Customer getWholeAddressOfCustomer:customer];
    NSString *color = @"";
    if([customer.status isEqualToString:@"1"])
    {
        color = @"Green";
    }else if ([customer.status isEqualToString:@"2"]) {
        color = @"Yellow";
    }else if ([customer.status isEqualToString:@"3"])
    {
        color = @"Red";
    }else {
        color = customer.status;
    }
    [geoCoder geocodeAddressString:customerAddress completionHandler:^(NSArray *placemarks, NSError *error) 
     {
         [NSThread sleepForTimeInterval:0.25];
         if (placemarks.count == 0)
         {

             NSLog(@"No place for customer %@ was found",customerAddress);
         }

         CLPlacemark *placemark = [placemarks objectAtIndex:0];

         if(placemark.location.coordinate.latitude != 0.000000 && placemark.location.coordinate.longitude != 0.000000)
         {
             CustomerAnnotation *annotation = [[CustomerAnnotation alloc]initWithCoordinate:placemark.location.coordinate andName:customer.name andNumber:customer.customerNo andColor:color];  

             [self.mapAnnotations addObject:annotation];

         }

     }];

}
CLLocationDegrees totalLatitude=0;
CLLocationDegrees totalLongitude = 0;
for (int i=0; i < [self.mapAnnotations count]; i++) {
    totalLatitude += [(CustomerAnnotation *)[self.mapAnnotations objectAtIndex:i] coordinate].latitude;
    totalLongitude += [(CustomerAnnotation *)[self.mapAnnotations objectAtIndex:i] coordinate].longitude;
    [self.mapView addAnnotation:[self.mapAnnotations objectAtIndex:i]];

}

MKCoordinateRegion focusRegion;
focusRegion.center.latitude = totalLatitude/[self.mapAnnotations count];
focusRegion.center.longitude = totalLongitude/[self.mapAnnotations count];
focusRegion.span.latitudeDelta = 20; //will modify this parameter later to self adapt the map
focusRegion.span.longitudeDelta = 20;
[self.mapView setRegion:focusRegion animated:YES];

But the problem is the timing issue like This problem

The setRegion is executed prior to obtaining those place marks. In the solution raised of that link, I should call a method in the completion block. But this solution is not suitable to a multiple address issue as I need to add all place marks to my method before I setRegion.

Is there anyway to make a method be executed after obtaining all results from geocodeAddressString?

Thanks in advance.

  • 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-10T19:17:14+00:00Added an answer on June 10, 2026 at 7:17 pm

    Issue resolved.

    Outside of the block, I used a counter to record the annotation added.

    __block int customerCount = 0; 
    

    When this count equals to the whole number, auto focus the central area of all customer.

    if (customerCount == [customers count]) {
       //Set the focus
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been writing Python code for only a couple of weeks, so I'm
I have only one class with many instances. Every instance is observer of couple
I have an application with many views. I want only a couple of the
I have a couple of simple forms that send an html-only email. Most clients
I have been using Uploadify in my PHP application for the last couple months,
I have implemented a couple of months ago the in app auto renewable subscription
I've been writing perl code full-time for a couple months now(bioinformatics), and am always
I have been learning to use hibernate for a couple of months. I am
I only got into PHP a few months ago and have been dabbing into
I have been working on an app for a couple of months now, but

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.