Hi all,
I am developing an iPhone application in which I want to show nearest restaurants based on the current location For that In the applicationDidFinishLaunching I am doing this :
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
NSURL *url = [[NSURL alloc] initWithString:@"http://192.168.0.150/server1/Service.asmx/nearest?lat1=23.013163&lon1=72.559068"];
NSMutableURLRequest* request2=[NSMutableURLRequest requestWithURL:url];
[request2 setHTTPMethod:@"GET"];
[request2 setTimeoutInterval:10];
NSURLResponse *response=nil;
NSError *err=nil;
NSData *data1=[[NSURLConnection sendSynchronousRequest:request2 returningResponse:&response error:&err] retain];
if(data1 == nil)
{
UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"The network is not available.\n Please check the Internet connection." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else
{
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data1];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
@try {
BOOL success = [xmlParser parse];
if(success)
NSLog(@"No Errors");
else
NSLog(@"Error Error Error!!!");
}
@catch (NSException * e) {
NSLog(@"Exception in parsing %@ %@",[e name], [e reason]);
}
}
The problem scenario.
the location manager start updating the location
The webservice gets executed before that so I can't get the location values .
I I am putting the web service call in the delegate method then the application launches before the web service gets executed. in the delegate method I am setting the latitude and longitude in the appropriate strings.
The Problem is that how ensure that the service will not be called until the location manager updates that location and then pass the location to the web service and then call that web service ..