I follow the Tutorial on the Internet, and I have 2 methods that send a request to the Google Places API. Unfortunately, I am trying to get an answer; it does not work. I have several debug numbers in the code. However, here is the code.
-(void) queryGooglePlaces{
NSString *url = @"https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=myKey";
NSURL *googleRequestURL=[NSURL URLWithString:url];
NSLog(@"1.5");
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL: googleRequestURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
NSLog(@"2");
}
-(void)fetchedData:(NSData *)responseData {
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
NSArray* places = [json objectForKey:@"results"];
NSLog(@"Google Data: %@", places);
NSLog(@"3");
}
In the log, the output is as such:
2012-08-03 16:40:12.411 sCode[25090:1a303] 1.5
2012-08-03 16:40:12.411 sCode[25090:1a303] 2
2012-08-03 16:40:12.512 sCode[25090:1a303] 4
2012-08-03 16:40:12.751 sCode[25090:1a303] Google Data: (
)
2012-08-03 16:40:12.751 sCode[25090:1a303] 3
2012-08-03 16:40:13.628 sCode[25090:1a303] 1
2012-08-03 16:40:14.129 sCode[25090:1a303] 4
Can someone tell me what is going wrong, so I have not received an answer.? yes, I typed [self queryGooglePlaces];in my method ViewDidLoad
Appreciate guys help! Sorry if I'm too verbose ... just a starter trying to learn!
source
share