我正在为我的 iOS 应用程序使用 Google Places API。我已启用 Google Maps Android API v2,来自 API 控制台的 Places API。在 API 访问部分创建一个 iOS key 。我正在使用以下代码向 Google Places API 发出请求:
NSString *finalString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=5000&keyword=restaurants&sensor=false&key=PASTE_GENERATED_KEY_HERE",_location.coordinate.latitude,_location.coordinate.longitude];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:finalString]];
但我在 JSON 响应中得到关注
{
"debug_info" = (
);
"html_attributions" = (
);
results = (
);
status = "REQUEST_DENIED";
}
我已经重新生成了不起作用的新 key 。有人可以弄清楚我在这里做错了什么。
最佳答案
“...Google Places API 当前不支持从 Google API 控制台生成的 iOS key 。目前仅支持服务器和浏览器 key ..”
...如果您想请求此支持,请提交 Places API - Feature Request ..”
从这个答案:https://stackoverflow.com/a/14744513/1702413
您可以使用 Google Maps JavaScript API v3 (Places Library of the Google Maps API v3)
或者..
在 iOS 上工作.. 如果您使用的是像 Sencha Touch 这样的 HTML5 移动应用程序框架.. 您可以查看本教程 Create a Location-Aware Site with Sencha Touch
更新
如果您使用 Key for browser apps (with referers)
,则可以正常工作从 API 控制台
例如(我正在使用 AFNetorking):
NSURL *url = [NSURL URLWithString:@"https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurants+in+Sydney&sensor=true&key=yourKEYforBrowser"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSArray *result = [JSON valueForKeyPath:@"results"];
NSLog(@"Google Resp: %@", result);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
{
NSLog(@"error");
}
];
[operation start];
关于iphone - Google Places API 响应状态 "Request_Denied",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17692930/