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
Is
findDistanceBetween:and:defined in an@implementationblock? Your code should look something likeIt may make more sense to put these types of methods on the Coordinate class itself so you can just do something like:
Don’t worry about anyone hating, we were all new at this once. 🙂