Reputation: 655
How to find city name in iPhone SDKs from google api?
http://maps.googleapis.com/maps/api/geocode/json?address=YOURADDRESS&sensor=true
Upvotes: 0
Views: 552
Reputation: 655
Firstly you create google api key at this link and then insert it into the code below.
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]];
Upvotes: 3