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 回答