Google APIからiPhone SDKで都市名を見つける方法は?
http://maps.googleapis.com/maps/api/geocode/json?address=YOURADDRESS&sensor=true
Google APIからiPhone SDKで都市名を見つける方法は?
http://maps.googleapis.com/maps/api/geocode/json?address=YOURADDRESS&sensor=true
まず、このリンクで 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]];