ios - 如何仅以英文获取 Googleapis 响应?

标签 ios objective-c xcode google-maps google-api

我正在使用 googleapis 服务获取用户的位置、当前城市名称 + 国家/地区名称:

NSString *urlString = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/xml?latlng=%f,%f&sensor=false",latitude,longitude];

urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL *url = [NSURL URLWithString:urlString];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

// Send the request
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

我得到一个包含数据的 XML 文件,而不是使用 NSXMLParser 来获取必要的信息。 由于某种原因,信息有时英文,有时不是,我需要英文。

我试图用这段代码覆盖应用程序的语言:

[[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:@"en", nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];

但是没有任何反应,我该怎么办?

最佳答案

Google Maps API Documentation ,它说:

Optional parameters in a geocoding request:

language — The language in which to return results. See the list of supported domain languages. Note that we often update supported languages so this list may not be exhaustive. If language is not supplied, the geocoder will attempt to use the native language of the domain from which the request is sent wherever possible.

因此,您只需在请求中将语言指定为参数即可。 对于英语:language=en

关于ios - 如何仅以英文获取 Googleapis 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28413533/

相关文章:

iOS UITextField 和 NSTimer 奇数

ios - 构建 map 应用程序 ios 时出现 fatal error

ios - 通知在凌晨 12 点而不是早上 7 点发送

objective-c - OCUnit 测试嵌入式框架

objective-c - Xcode中有逐行调试方法吗?

ios - UICollectionViewCell 嵌入导航 Controller 时下推

iphone - NSTimers 和 NSRunLoops 的不稳定行为

ios - 用于验证 API 的 OAuth2 - 无法重定向回我的应用程序

ios - cellForRowAtIndexPath 对第一个以外的任何部分返回 nil

ios - 当我将 UIKit 元素添加到 subview 时,setFrame 不起作用