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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:52:02+00:00 2026-05-26T04:52:02+00:00

So I have a model object, which is a named ‘location’ which has a

  • 0

So I have a model object, which is a named ‘location’ which has a set of properties on. One of which is ‘distanceFromUserLocation‘. Obviously, to know this it needs to know the user’s location, so in the model object I am calculating the user’s current location.

This also sets a CLLocation property on this model every time on the didUpdateToLocation method.

I also have an initWithDictionary method on the model which sets all the values for properties on the location model.

code below for my model:

@synthesize name = _name;
@synthesize entryLocation = _entryLocation;
@synthesize address = _address;
@synthesize contactNumber = _contactNumber;
@synthesize distanceFromUserLocation = _distanceFromUserLocation;
@synthesize itemDescription = _itemDescription;
@synthesize locationManager = _locationManager;
@synthesize userLocation = _userLocation;


-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation        *)newLocation fromLocation:(CLLocation *)oldLocation
{
    if (newLocation != nil) {
        self.userLocation = newLocation;
        NSLog(@"lat: %@ lon: %@ ", [NSString stringWithFormat:@"%.7f",   newLocation.coordinate.latitude], [NSString stringWithFormat:@"%.7f", newLocation.coordinate.longitude]);
    }

    [manager stopUpdatingLocation];
}

-(id)initWithDictionary:(NSDictionary*) dictionary
{
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;

    [self.locationManager startUpdatingLocation];

    self = [super init];
    if (self) 
    {
        self.name = [dictionary valueForKey:@"Name"];
        self.address = [dictionary valueForKey:@"Address"];
        self.contactNumber = [dictionary valueForKey:@"ContactNumber"];
        self.itemDescription = [dictionary valueForKey:@"Description"];
        double lat = [[dictionary valueForKey:@"Latitude"] doubleValue];
        double lon = [[dictionary valueForKey:@"Longitude"] doubleValue];
        self.entryLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
        self.distanceFromUserLocation = [self.userLocation distanceFromLocation:self.entryLocation];
    }

    return self;
}

The problem I have, is that in the didUpdateToLocation, I am setting the ‘self.currentLocation‘ property to the value of newLocation. I then log the lat and the long to make sure i actually have a value, which I do.

However, when i then initialize an instance of the ‘Location’ model from my controller class and then log the value for currentLocation on that model object:

NSLog(@"%@", location.currentLocation);

I get (null) in the log.

If i try:

NSLog(@%@", location.currentLocation.coordinate.latitude);

I get a EXC_BAD_ACCESS error.

I am successfully getting the current location in the didUpdateToLocation and loggint it, but then why when I set my currentLocation property to the value of newLocation does it not get retained?

Any help with this would be greatly appreciated 🙂

  • 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-05-26T04:52:03+00:00Added an answer on May 26, 2026 at 4:52 am

    So it turns out the EXC_BAD_ACCESS error was down to what joost and JBat100 suggested. Just down to using %@ instead of %f. I did however figure out why I couldn’t ever get the user location value out of the property on the controller. The methods are called asynchronously and the forRowAtIndexPath method was rendering the table cells BEFORE user location could ever be found, so the pointer to userlocation was pointing to nothing when it was called.

    I solved it by adding a view with an activity indicator which finds the user location, saves it to a property and THEN pushes the view with the table in onto the screen, setting it’s userlocation property that way so that the property is never empty 🙂

    Thanks for the help everyone!

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

Sidebar

Related Questions

Say I have a model object 'Person' defined, which has a field called 'Name'.
I have a fairly involved managed data model which has a central object with
I have an object, RenderComponent , that has a property named Model that is
I have a model named 'Object' which loads the 'Objects' table I have a
When I have a CoreData entity named, say, 'Book', which has a one-to-one relationship
I have a project which exposes object model to use by different types of
I have a model which gets its data from a parser object. I'm thinking
If I have Model.objects.all() I want to get only one object for any content_object=foo,
The GoDiagram object model has a GoDocument. GoViews have a reference to a GoDocument.
I have a model service and a ModelForm named Service which I use to

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.