I am using Google places API to search for nearby places. I make one call to get the places, and another call to get the phone number of the places. The second call is slowing down the app. Any way around this? If some sample code could be provided as well that would be great.
s1 = [NSString stringWithFormat:@"https://api.foursquare.com/v2/venues/explore?client_id=%@&client_secret=%@&query=%@&v=20201212&m=swarm&sortByDistance=%i&radius=%f&limit=%@&ll=%f,%f", kClientID, kClientSecret, Name, sortByDistance, meterRadius, recorddisplay, lat, lng];
NSLog(@"This is the foursqaure query: %@", s1);
NSURL *jsonURL = [NSURL URLWithString:[self urlEncodeValue:s1]];
NSString *jsonDataString = [[NSString alloc]initWithContentsOfURL:jsonURL];
NSData *jsonData = [jsonDataString dataUsingEncoding:NSUTF8StringEncoding];
//NSLog(@"This is JSON data: %@", jsonDataString);
if(jsonData == nil)
{
NSLog(@"SEARCH RESULT IS NIL.....");
//[pool release];
return FALSE;
}
else
{
//retrieve the objects in the JSON and then make another http request...
}
This line is wrong:
NSString *jsonDataString = [[NSString alloc]initWithContentsOfURL:jsonURL];
You are networking synchronously on the main thread. Never never never do that. That's the cause of the delay.