我有这个:
//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);
这会吐出一些结果,其中第一个是我想要的结果,但我无法像使用其他 API 那样得到 lat 和 lng:
NSString *stringLatitude = [locationResults objectForKey:@"lat"];
我怀疑它正在寻找的键是“结果”键的一个子集,我不知道如何告诉它:-(
结果:
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";
};
viewport = {
northeast = {
lat = "-33.4245981";
lng = "151.3426361";
};
southwest = {
lat = "-34.1692489";
lng = "150.502229";
};
};
};
感谢任何指导!