0

Google APIからiPhone SDKで都市名を見つける方法は?

http://maps.googleapis.com/maps/api/geocode/json?address=YOURADDRESS&sensor=true

4

1 に答える 1

3

まず、このリンクで Google API キーを作成し、それを以下のコードに挿入します。

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];

[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%@&sensor=true&key=<your api key here>",your_textField_search_str]]];
[request setHTTPMethod:@"POST"];

NSError *error;
NSURLResponse *response;
NSData *returnData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

NSString *returnString=[[NSString alloc]initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@",returnString);  
SBJSON *json = [[SBJSON new] autorelease];
dic = [[NSMutableDictionary alloc] initWithDictionary:[json objectWithString:returnString error:nil]];
于 2012-06-20T13:23:27.630 に答える