Capturing current location and calculating distance
<p>I've been looking at this for a while. I've found plenty of posts and looked at the documentation but I'm having trouble getting it working. I have core location implemented, and its working with no problems i.e.</p>

<pre><code>NSLog(@"Description: %@\n", [newLocation description]);
</code></pre>

<p>The description details are displayed in the log.</p>

<p>I want to capture the current location when the user taps on a button and as they start to move recapture their location intermittently. Using this information I want to calculate the distance between the starting point and the current point. </p>

<p>I know I can use the following:</p>

<pre><code>CLLocationDistance distance = [myLocation distanceFromLocation:restaurantLocation]
</code></pre>

<p>to calculate the distance but I'm not sure how to capture the current location.</p>

<p>If anyone could post some sample code that would be great. I close to getting this working, just need a final push over the line.</p>

<p>Regards,
Stephen</p>

<p><strong>Part 2: Since the original post, I've made a bit of progess. Details posted below:</strong></p>

<pre><code>#import "MyCLController.h"


@implementation MyCLController

@synthesize locationManager;
@synthesize delegate;

- (id) init {
    self = [super init];
    if (self != nil) {
        self.locationManager = [[[CLLocationManager alloc] init] autorelease];
        self.locationManager.delegate = self; // send loc updates to myself
    }
    return self;
}

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
    [self.delegate locationUpdate:newLocation];

    CLLocation *item1 = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];
    CLLocation *item2 = [[CLLocation alloc] initWithLatitude:oldLocation.coordinate.latitude longitude:oldLocation.coordinate.longitude];

    int meters = [item1 getDistanceFrom:item2]; 
    NSLog(@"Distance-d: %d", meters);

    [item1 release];
    [item2 release];


}


- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error
{
    [self.delegate locationError:error];
}

- (void)dealloc {
    [self.locationManager release];
    [super dealloc];
}

@end
</code></pre>

<p>Am I right to calculate the distance here or should I be doing it in NewWorkoutViewController.m, in the locationUpdate method ?</p>
