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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:51:57+00:00 2026-06-09T16:51:57+00:00

I am querying Google for lat/long points for a map view. This can take

  • 0

I am querying Google for lat/long points for a map view. This can take a long time depending on how many addresses the user has put into the app, as the map views all of them. I also introduced a short delay between querying in the for loop to make sure that Google gives me good results (if you query too quickly it doesn’t give you valid lat/long points but 0,0).

Because this takes so long, once the user presses the button to go to this UIViewController it takes a long time and I’m afraid the user will think the app is broken. I would ideally like the ViewController to “show up” but have an map (without annotations initially) with an animated activity indicator over the map until it’s finished querying, and then load the annotations. That way the user can look at the other information on the view while waiting for the map to load.

Here is my code:

- (void) viewDidLoad {
    [mapScroll startAnimating]; // activity indicator outlet
    [self makeMap];
    // ... etc.
}

- (void)makeMap {
allRegions = [[NSMutableArray alloc] init];
[self getDistinctRegions]; //generates allRegions array

double maxLat = -90;
double maxLon = -180;
double minLat = 90;
double minLon = 180;

for (int i=0; i<[allRegions count]; i++) {
    NSString *tempString = [allRegions objectAtIndex:i];
    NSString *searchString = [tempString stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
    NSString *queryURL = [[NSString alloc] initWithFormat:@"http://maps.google.com/maps/geo?output=csv&q=%@",searchString];
    NSString *queryResults = [[NSString alloc] initWithContentsOfURL: [NSURL URLWithString:queryURL] encoding: NSUTF8StringEncoding error:nil];
    NSArray *queryData = [queryResults componentsSeparatedByString:@","];

    if ([queryData count] == 4) {
        double latitude = [[queryData objectAtIndex:2] doubleValue];
        double longitude = [[queryData objectAtIndex:3] doubleValue];

        if (latitude > maxLat) maxLat = latitude;
        if (latitude < minLat) minLat = latitude;
        if (longitude > maxLon) maxLon = longitude;
        if (longitude < minLon) minLon = longitude;

        CLLocationCoordinate2D coordinate;
        coordinate.latitude = latitude;
        coordinate.longitude = longitude;

        MKPlacemark *marker;
        marker = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil];
        [mapView addAnnotation:marker];

        NSLog(@"%d",i);

        [NSThread sleepForTimeInterval:0.12];
    }
}

MKCoordinateRegion overallRegion;

double latSpan = abs(maxLat - minLat);
double lonSpan = abs(maxLon - minLon);
double avgLatitude = (maxLat+minLat)/2;
double avgLongitude = (maxLon+minLon)/2;

overallRegion.center.latitude = avgLatitude;
overallRegion.center.longitude = avgLongitude;
overallRegion.span.latitudeDelta = latSpan;
overallRegion.span.longitudeDelta = lonSpan;

[mapView setRegion:overallRegion animated:YES];

[mapScroll stopAnimating];
mapScroll.hidden = TRUE;
}
  • 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-09T16:51:58+00:00Added an answer on June 9, 2026 at 4:51 pm

    Um, quick and dirty solution, but here is the general process:

    1) when user press Go button, you alloc-init your next view controller

    2) assuming you have a method to download your lat/long info and a method to render your pin, in your next view controller’s viewDidLoad method, you can do something like:

    -(void)viewDidLoad
    {
        ....
        [self performSelectorInBackground:@selector(downloadMapData) withObject:nil];
    }
    
    // your download map data method
    -(void)downloadMapData
    {
        // download data from Google API. I assume you know how to do this part.
    
        // when done, add map annotation points to map on the main thread
        // interface changes must be done on the main thread
        [self performSelectorOnMainThread:@selector(addPinToMap)];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Querying a Nested Set Model table , here's the SQL... how can this be
I'm querying an online service (google data feed) which can return results that will
I have been querying locations from a Google fusion table and mapping the points
I'm using GAPI library (in PHP) for querying Google Analytics API. I request 2
i'm querying a database like this: SELECT * from Log WHERE cookieId IN (select
I'm new to querying XML datatype in SQL Server 2005. Anyone can help me
I am querying a PostGIS database based on where a user clicks on a
I'm querying the Google Books API, and I'm parsing the books into a custom
i'm querying google calendar api to bring back dates between the start-min and start-max
I've got a question about Google App Engine and querying the datastore. Suppose I've

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.