// Method: What is Nearer helper function
// Pre-requisite: dataset loaded in the app delegate
-(NSDictionary *) whatIsNearer:(CLLocation *)currentLocation {
whichway_ipadAppDelegate *appdelegate = (whichway_ipadAppDelegate *)[[UIApplication sharedApplication] delegate];
float closest_distance;
int linecnt = 1;
NSDictionary *tmpDict = [[[NSDictionary alloc] init] autorelease];
for (NSDictionary *store in appdelegate.dataset) {
NSString *latlong = [store objectForKey:@"LatLong"];
NSArray *latlongarray = [latlong componentsSeparatedByString:@","];
CLLocationDegrees lat = [[latlongarray objectAtIndex:0] doubleValue];
CLLocationDegrees longitude = [[latlongarray objectAtIndex:1] doubleValue];
CLLocation *tmploc = [[[CLLocation alloc] initWithLatitude:lat longitude:longitude] autorelease];
CLLocationDistance current_dist = [tmploc distanceFromLocation:currentLocation];
if (linecnt == 1) {
closest_distance = current_dist;
tmpDict = store;
} else {
if (current_dist < closest_distance) {
tmpDict = store;
}
}
linecnt++;
}
return tmpDict;
}