I have an Xcode project which basically loads and parses a xml file which outputs a list a list of locations (venues) close to the users current location. I originally hard-coded the longitude and latitude co-ordinates to ensure my xml was parsing correctly (which it is), but now i'm attempting to pass the users current location to determine the closest locations to the user (similar to a store finder). I have a delegate class file which handles loading the xml file and a rootViewController file which handles the users current location. My issue is that i don't know the best way to pass the parameters from one class to a delegate class... Sorry i know it's basic but i'm struggling with it :)
Here two snippets of the basis of what i have:
RootViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Get Current Location
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
appDelegate = (XMLAppDelegate *)[[UIApplication sharedApplication] delegate];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"", degrees, minutes, seconds];
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"", degrees, minutes, seconds];
NSLog(@"longt Value: %@", longt);
}
XMLAppDelegate.m
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//This code is incorrect (displays 'null') I want to display the values defined in the locationManager Method on RootViewController.m
NSLog(@"lat Value: %@", currentLocation.coordinate.latitude);
// Longitude and Latitude codes are hard-coded. I want to change this to dynamic values which are defined in the locationManager Method on RootViewController.m
NSURL *url = [[NSURL alloc] initWithString:@"http://www.domain.com/phpsqlsearch_genxml.php?lat=-33.870017&lng=151.206547&radius=25"];
//More code here....
}
I'm able to display the results (NSLog) on the RootViewController.m file but not on the XMLAppDelegate.m file. I need to find out the best way to pass the parameters to the from RootViewController.m to XMLAppDelegate.m?
Please let me know if there is anymore information you require.
Cheers