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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:02:52+00:00 2026-06-06T21:02:52+00:00

I am new to ObjC and I am struggling with the CLGeocoder. I want

  • 0

I am new to ObjC and I am struggling with the CLGeocoder. I want to be able to use reverseGeocodeLocation to obtain a string that contains the user location that I pass to my delegate when the user presses a Done button.

So the user triggers the display of a MapViewController, I call the reverseGeocodeLocation in the viewDidLoad but the [placemarks count = 0] this first time in, and I have no placemark to get the info that I need. The second time the user triggers the display of the MapViewController the placemarks array has been populated and everything works.

I suspect it is something to do with the reverseGeocodeLocation being an asynchronous call – but I cannot figure out how to solve this problem. I have tried searching online but nothing seems to help me understand what I am doing wrong and how i can solve this issue. Thanks in advance.

@interface MapViewController ()
@property (strong, nonatomic) CLGeocoder *geocoder;
@property (readwrite, nonatomic) NSString *theLocationName;
@end

@implementation MapViewController
@synthesize mapView, geocoder, delegate = _delegate, theLocationName = _theLocationName;

- (void)viewDidLoad
{
[super viewDidLoad];

self.mapView.delegate=self;
self.mapView.showsUserLocation = YES;

[self theUserLocation];
}

-(void)theUserLocation
{
if (!geocoder)
{
    geocoder = [[CLGeocoder alloc] init];
}

MKUserLocation *theLocation;
theLocation = [self.mapView userLocation];

[geocoder reverseGeocodeLocation:theLocation.location 
               completionHandler:^(NSArray* placemarks, NSError* error)
 {
     if ([placemarks count] > 0)
     {
         CLPlacemark *placemark = [placemarks objectAtIndex:0];

         [self setTheLocationName: placemark.locality];

     }
 }];

- (IBAction)done:(id)sender 
{

[[self delegate] mapViewControllerDidFinish:self locationName:[self theLocationName]];

}

@end
  • 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-06T21:02:54+00:00Added an answer on June 6, 2026 at 9:02 pm

    So the user triggers the display of a MapViewController, I call the reverseGeocodeLocation in the viewDidLoad but the [placemarks count = 0] this first time in, and I have no placemark to get the info that I need. The second time the user triggers the display of the MapViewController the placemarks array has been populated and everything works.

    It’s not because the call is asynchronous – it’s because the first time you call theUserLocation the actual location isn’t available. Getting the user’s location is not instantaneous – it takes time. However, you’re asking for the user’s location as soon as the map loads, which in most circumstances won’t work.

    What you need to do is hook into the MKMapViewDelegate methods, which provide you with callbacks when the location is updated. You can use this to check the location’s accuracy, and decide whether it is accurate enough for you to reverse geolocate.

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

Sidebar

Related Questions

I'm still pretty new to ObjC. I noticed that it's pretty standard everywhere to
I'm new on objc/Cocoa and I never use C before. I've a problem to
Possible Duplicate: ObjC/Cocoa class for converting size to human-readable string? I'm new in Cocoa.
I am pretty new to OSX programming, or to the use of ObjC. I've
I'm quiet new in ObjC and app programming. All I want to do is
I am new to ObjC. If I want to declare instance variables for private
I have an objc program and i would like to use a widget that
I am new in iOS. I want to use CAEmitterLayer, which is only support
Im new to objC and Im currently experimenting on UISearchDisplayController. Basically I have an
Hi i'm fairly new to objC and i am hoping someone can help me

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.