6

我已经这样做了

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://maps.googleapis.com/maps/api/place/search/json?location=30.722322,76.76126&radius=500&types=food&sensor=true&key=any_apiKey"]];

    NSURLResponse *response;
    NSError *error;
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSString *strResponse = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    NSLog(@"%@",strResponse);

    SBJSON *sbJason = [[SBJSON alloc] init];
    NSMutableDictionary *getPlaceList = [sbJason objectWithString:strResponse]; 

//但我得到了这个-

   {
 "html_attributions" : [],
  "results" : [],
 "status" : "REQUEST_DENIED"
 }

**API 密钥有什么问题吗?我已经写了谷歌地图给出的 API 密钥。api密钥有什么问题吗或者请告诉我这里是google api的链接

4

6 回答 6

20

尽管已经回答了这个问题,但我认为社区可以更好地解释实际需要做什么才能使其正常工作。

我为此烦恼不已,这对我来说没有意义..我正在制作一个iOS / Android应用程序,所以我制作了一个iOS / Android密钥...... 错了。

使用 Google 的 Places API,甚至不会考虑您的捆绑标识符。

你真正想做的是:(我正在使用新的用户界面)

1. 登录https://cloud.google.com/console#/project

选择您的项目名称,然后进入API's & Auth > APIs

确保您已打开 Places API。这是唯一需要打开 Places-API 才能工作的东西。 在此处输入图像描述

2.进入凭证

单击公共 API 访问下的创建新密钥 在此处输入图像描述

3. 选择浏览器密钥 在此处输入图像描述

4.点击创建,没有别的

将 HTTP 引用框留空。

在此处输入图像描述

5.使用这里生成的密钥

此密钥将允许来自任何设备的任何用户通过您的开发人员登录访问 API。您可以在这里尝试一下:(请务必将YOUR_KEY_HERE替换为您生成的密钥)

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Food%20Sh&sensor=false&radius=500&location=0,0&key=YOUR_KEY_HERE

6.享受

现在您可以在您的 Android/iOS 设备中使用上面的 URL。

于 2013-12-27T07:41:29.707 回答
4

尝试使用 BROWSER 应用程序密钥,而不是 iOS 密钥。你可以在这里找到它:

https://code.google.com/apis/console/

然后按左侧的“API Access”

于 2013-03-29T20:24:19.507 回答
2

Static Maps API 和 Places API 都需要在 API 控制台中为该密钥启用。打开 API 控制台并启用对 Places API 的访问。有一个礼貌限制:每天 1,000 个请求,之后您可能需要启用计费。

https://code.google.com/apis/console/

于 2012-09-05T10:45:36.813 回答
2

只想支持乔希的解决方案。我花了几个小时弄清楚 IOS 密钥,几乎放弃了。

于 2013-04-16T17:23:45.290 回答
1

试试这个:-

https://developers.google.com/places/documentation/

阅读以下部分并继续执行获取密钥的步骤。

验证

Google Places API 使用 API 密钥来识别您的应用程序。API 密钥通过 Google API 控制台进行管理。在开始使用 API 之前,您需要自己的 API 密钥。要激活 Places API 并创建您的密钥:

Visit the APIs console at https://code.google.com/apis/console and log in with your Google Account.
A default project called API Project is created for you when you first log in to the console. You can use the project, or create a new one by clicking the API Project button at the top of the window and selecting Create. Maps API for Business customers must use the API project created for them as part of their Places for Business purchase.
Click the Services link from the left-hand menu.
Click the Status switch next to the Places API entry. The switch slides to On.
Click API access from the left navigation. Your key is listed in the Simple API Access section.
于 2012-09-05T07:00:51.910 回答
0

我最终得到了这段代码。

UIActivityIndicatorView *activity=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activity.center=self.view.center;
[activity startAnimating];
[self.view addSubview:activity];


NSString *str=[[NSString alloc] init];
str=[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/textsearch/json?query=%@&sensor=true&key=YOUR_BROWSER_KEY",searchQuery];
NSMutableURLRequest *request1=[[NSMutableURLRequest alloc] init];
NSURL *url= [[NSURL alloc] initWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[request1 setURL:url];
[request1 setHTTPMethod:@"GET"];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    NSError *requestError = nil;
    NSURLResponse *urlResponse = nil;
    NSData *response1 =
    [NSURLConnection sendSynchronousRequest:request1
                          returningResponse:&urlResponse error:&requestError];


    dispatch_async(dispatch_get_main_queue(), ^{


        if ([activity isAnimating]) {
            [activity startAnimating];
            [activity removeFromSuperview];
        }
        NSError* error;
        NSDictionary* json = [NSJSONSerialization JSONObjectWithData:response1
                                                             options:kNilOptions
                                                               error:&error];

        NSLog(@"%@",json);

        self.searchArray=[json objectForKey:@"results"];
        [self.tableView setDataSource:self];
        [self.tableView setDelegate:self];
        [self.tableView reloadData];

        [self showPins:self.searchArray];

    });
});
于 2015-10-06T06:23:56.467 回答