Stephen Stephen - 1 year ago 438
iOS Question

distanceFromLocation - Calculate distance between two points

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 Source

Try this instead:

CLLocationDistance meters = [newLocation distanceFromLocation:oldLocation];

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