I have to do a project in which I have to calculate the distance from my location which is detected by gps to a number of restaurants whose locations are in a plist file and then display the distance in a list view as a subtitle of the restaurant name.
I know about the CLLocationDistance
and I wrote one function which is :-
-(double)distanceBetPoints
{
CLLocation *user = [[CLLocation alloc] initWithLatitude:locationManager.location.coordinate.latitude longitude:locationManager.location.coordinate.longitude];
CLLocationDistance distance = [user distanceFromLocation:restaurant.location];
return distance;
}
Here location manager is determining my location and restaurant.location
is the location entry in the plist file.
I have written the following in the cell configuration :-
NSString *d = [NSString stringWithFormat:@"%@",[mapVC.distanceBetPoints]];
cell.detailTextLabel.text = [@"%@",[d]];
Here mapVC
is my object of mapVC
class where the method for distance calculation exists, both these lines are giving me an error for expected identifier.
Also how do I calculate it separately for every restaurant and show it in tableview? do I have to store the values in an array or something? If yes than where should I put my method and where should I call it so that it gets calculated for every restaurant and stored in an array..