distanceFromLocation - Calculate distance between two points

Stephen picture Stephen · Oct 11, 2010 · Viewed 83.4k times · Source

Just a quick question on Core Location, I'm trying to calculate the distance between two points, code is below:

    -(void)locationChange:(CLLocation *)newLocation:(CLLocation *)oldLocation
    {   

    // Configure the new event with information from the location.
        CLLocationCoordinate2D newCoordinate = [newLocation coordinate];
        CLLocationCoordinate2D oldCoordinate = [oldLocation coordinate];

        CLLocationDistance kilometers = [newCoordinate distanceFromLocation:oldCoordinate] / 1000; // Error ocurring here.
        CLLocationDistance meters = [newCoordinate distanceFromLocation:oldCoordinate]; // Error ocurring here.
}

I'm getting the following error on the last two lines:

error: cannot convert to a pointer type

I've been searching Google, but I cannot find anything.

Answer

deanWombourne picture deanWombourne · Oct 11, 2010

Try this instead:

CLLocationDistance meters = [newLocation distanceFromLocation:oldLocation];

The method you're trying to use is a method on a CLLocation object :)