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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:42:29+00:00 2026-05-22T01:42:29+00:00

I’m sort of a newbie–please don’t hate. The method compiles, but I’m not sure

  • 0

I’m sort of a newbie–please don’t hate.

The method compiles, but I’m not sure how to actually retrieve the float value (i.e. the distance between the two points) that the method returns (or should return rather).

-(float)findDistanceBetween:(Coordinate *)a and:(Coordinate *)b
{
//distance formula: 
//sqrt( (x2 - x1)^2 + (y2 - y1)^2 )

float resultDistance; 

resultDistance = sqrt( pow((b.latitude - a.latitude), 2) + pow((b.longitude - a.longitude), 2));

return resultDistance;  
}

//Somewhere else...

float theDistanceBetween; 

//Below is incorrect:

theDistanceBetween = [findDistanceBetween: location1 and: location2]; 

Thanks

  • 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-22T01:42:29+00:00Added an answer on May 22, 2026 at 1:42 am

    Is findDistanceBetween:and: defined in an @implementation block? Your code should look something like

       // in the .h file
    
       @interface MyClass : NSObject
    
       // declaration of the method
       - (float)findDistanceInBetween:(Coordinate *)a and:(Coordinate *)b;
       @end
    
       // in the .m file
    
       @implementation MyClass
    
       // definition of the method
       - (float)findDistanceBetween:(Coordinate *)a and:(Coordinate *)b {
           return sqrt(powf(a.x - b.x, 2.f) + powf(a.y - b.y, 2.f));
       }
       @end
    
       // then somewhere else that needs to calculate the difference:
       // (assume coord_a and coord_b already exist)
    
       // create an instance of MyClass
       MyClass *myInstance = [[MyClass alloc] init];
    
       // send the `findDistanceBetween:and:` message to the instance
       float distance = [myInstance findDistanceBetween:coord_a and:coord_b];
    
       // when you're done with the instance, you need to clean up
       [myInstance release];
    

    It may make more sense to put these types of methods on the Coordinate class itself so you can just do something like:

       Coordinate *coord_a = <get the coordinate from somewhere>;
       Coordinate *coord_b = <get the coordinate from somewhere>;
    
       float distance = [coord_a distanceFrom:coord_b];
       float angle = [coord_a angleTo:coord_b];
    

    Don’t worry about anyone hating, we were all new at this once. 🙂

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.