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

  • Home
  • SEARCH
  • 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 7775715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:42:05+00:00 2026-06-01T17:42:05+00:00

I am trying to understand the crash log. It happens when I try to

  • 0

I am trying to understand the crash log. It happens when I try to perform the CLLocationDistance method distanceFromLocation. In order to get two locations I need to geocode, but I need one block so I can have those two instance variables. So I direct it to a method with parameters:

  - (void)geoCodeSetup:(NSArray *)placemarks :(NSError *)error andIdentifier:(NSString *)string {
CLLocation *location1;
CLLocation *location2;
if ([string isEqualToString:@"Origin"]) {
    if (!error) {
        CLPlacemark *place = [placemarks objectAtIndex:0];
        CLLocation *location = place.location;
        location1 = [[CLLocation alloc] initWithLatitude:location.coordinate.latitude longitude:location.coordinate.longitude];

    } else {
        NSString *string = [NSString stringWithFormat:@"%@ - also make sure you have inputted a valid city", [error localizedDescription]];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:string delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
    }
}

if ([string isEqualToString:@"Destination"]) {
    if (!error) {
        CLPlacemark *place = [placemarks objectAtIndex:0];
        CLLocation *location = place.location;
       location2 = [[CLLocation alloc] initWithLatitude:location.coordinate.latitude longitude:location.coordinate.longitude];


    } else {
        NSString *string = [NSString stringWithFormat:@"%@ - also make sure you have inputted a valid city", [error localizedDescription]];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:string delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
    }
}


CLLocationDistance distanceM = [location1 distanceFromLocation:location2];    
[metreDistance setText:[NSString stringWithFormat:@"%f", distanceM]];

}

- (IBAction)calculateDistance {

[textFieldDestination resignFirstResponder];
NSString *origin = [textFieldOrigin text];
if (origin) {
    CLGeocoder *geoCode = [[CLGeocoder alloc] init];

    [geoCode geocodeAddressString:origin completionHandler: ^(NSArray *placemarks, NSError *error) {
        NSArray *p1 = placemarks;
        NSError *e1 = error;
        [p1 retain];
        [e1 retain];
        [self geoCodeSetup:p1 :e1 andIdentifier:@"Origin"];


    }]; 
}

NSString *destination = [textFieldDestination text];
if (destination) {

    CLGeocoder *geoCode2 = [[CLGeocoder alloc] init];

    [geoCode2 geocodeAddressString:destination completionHandler:^(NSArray *placemarks, NSError *error) {
        NSArray *p2 = placemarks;
        NSError *e2 = error;
        [p2 retain];
        [e2 retain];
        [self geoCodeSetup:p2 :e2 andIdentifier:@"Destination"];




    }]; 
}

It crashes/gives EXC_BAD_ACCESS (code =EXC_ARM_DA_ALIGN, address=.....etc....) on the distanceFromLocation part. I have attached a screenshot of the crash log.

Crash Log

What might cause this and how do I solve it?

  • 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-01T17:42:06+00:00Added an answer on June 1, 2026 at 5:42 pm

    I assume that location1 or location2 is not set because you did wrap it into

    if ([string isEqualToString:@"Origin"]) {
        if (!error) {
    

    You might avoid the crash by chaining line 2 and 3 to:

    CLLocation *location1 = nil;
    CLLocation *location2 = nil;
    

    and maybe you need also to change line:

    CLLocationDistance distanceM = [location1 distanceFromLocation:location2]; 
    // change to
    CLLocationDistance distanceM;
    if(location1 && location2) {
      distanceM = [location1 distanceFromLocation:location2];
    }
    

    i think you run distanceFromLocation: with at least one NULL parameter or object.

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

Sidebar

Related Questions

I'm trying to understand debug output from a crash log. I have the following
Trying to understand the options for will_paginate's paginate method: :page — REQUIRED, but defaults
I'm trying to understand blocks. I get how to use them normally, when passed
When I crash (for reasons I understand; that's not the problem) when I try
I'm trying to interpret this crash log below, but I'm not sure if I
Trying to understand Ruby a bit better, I ran into this code surfing the
Trying to understand something. I created a d:\svn\repository on my server. I committed folders
Trying to understand the math of this code snippet. A token is provided which
I trying to understand if a isset is required during form processing when i
Just trying to understand that - I have never used it before. How is

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.