我有这个:
//request stuff
NSString *searchString = [NSString stringWithFormat:@"Sydney"];
NSString *urlString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/textsearch/json?query=%@&sensor=true&key=mykeynotyours!",searchString];
NSURL *requestURL = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:(requestURL)];
//response
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSError *jsonParsingError = nil;
NSDictionary *locationResults = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError];
NSLog(@"%@",locationResults);
Run Code Online (Sandbox Code Playgroud)
哪个是吐出一些结果,第一个是我想要的结果,但我不能像其他API一样得到lat和lng说:
NSString *stringLatitude = [locationResults objectForKey:@"lat"];
Run Code Online (Sandbox Code Playgroud)
我怀疑它正在寻找的关键是"结果"键的一个子集,我不知道如何告诉它:-(
结果:
2013-04-12 18:47:49.784 Test[26984:c07] {
"html_attributions" = (
);
results = (
{
"formatted_address" = "Sydney NSW, Australia";
geometry = {
location = {
lat = "-33.8674869";
lng = "151.2069902"; …Run Code Online (Sandbox Code Playgroud)