Sto seguendo uno Tutorial online e ho 2 metodi che inviano una query all'API di Google Places. Sto cercando di ottenere una risposta, purtroppo, non funziona. Ho alcuni numeri di debug nel codice. Tuttavia, ecco il codice.API Google Places Non restituisce una risposta
-(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";
//Formulate the string as a URL object.
NSURL *googleRequestURL=[NSURL URLWithString:url];
NSLog(@"1.5");
// Retrieve the results of the URL.
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL: googleRequestURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
NSLog(@"2");
}
-(void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
//The results from Google will be an array obtained from the NSDictionary object with the key "results".
NSArray* places = [json objectForKey:@"results"];
//Write out the data to the console.
NSLog(@"Google Data: %@", places);
NSLog(@"3");
}
Sul registro l'uscita va come tale:
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
Qualcuno può dirmi che cosa sta andando male, quindi non didn ottenere una risposta.? sì, ho chiamato lo [self queryGooglePlaces];
nel mio metodo ViewDidLoad
Apprezzo l'aiuto ragazzi! Scusate se sono troppo prolisso .. proprio un antipasto che cerca di imparare!
bene il mio URL è diverso tuttavia, questo particolare URL, ho tirato direttamente fuori dal sito API di Google Places e semplicemente sostituito la mia chiave API. Quindi pensi che il problema risieda solo nell'URL? –
L'URL esatto è irrilevante per il tuo problema. Sto parlando specificamente di come quell'URL è codificato prima di inviarlo al server per l'elaborazione. –
anche quando ho aggiunto quella riga di codice non ho ricevuto risposta :( –