Ich verfolge online eine Tutorial und ich habe 2 Methoden, die eine Anfrage an die Google Places-API senden. Ich versuche leider eine Antwort zu bekommen, es funktioniert nicht. Ich habe ein paar Debug-Nummern im Code. Hier ist jedoch der Code.Google Places API Keine Antwort zurückgegeben
-(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");
}
Auf dem Protokoll geht der Ausgang als solche:
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
jemand kann mir sagen, was los ist falsch so didn ich keine Antwort bekommen.? ja ich rief [self queryGooglePlaces];
in meinem ViewDidLoad
Methode Schätzen Sie die Hilfe Jungs! Entschuldigung, wenn ich zu verbose..just ein Starter versucht zu lernen!
gut meine URL ist anders jedoch diese spezielle URL, zog ich direkt von der Google Places API-Website und ersetzt einfach meinen API-Schlüssel. Also denken Sie, das Problem liegt nur in der URL? –
Die genaue URL ist für Ihr Problem nicht relevant. Ich spreche speziell darüber, wie diese URL codiert ist, bevor sie zur Verarbeitung an den Server gesendet wird. –
selbst wenn ich diese Zeile Code hinzugefügt habe ich bekam keine Antwort :( –