6

I have done that

    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]; 

// But i am getting this-

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

**Is there any problem with API Key i have wrote API key given by google map. Is there any problem with api key or what please tell me here is the link of google api

Prabhjot Singh Gogana
  • 1,408
  • 1
  • 14
  • 39

4 Answers4

20

Although this has been answered, I think the community could do better in explaining what ACTUALLY needs to be done in order to get this working.

I was tearing my hair out about this, it just didn't make sense to me.. I was making an iOS/Android App, so I made an iOS/Android Key... Wrong.

With Google's Places API, your bundle identifier isn't even considered.

What you really want to do is this: (I'm using the new User Interface)

1. Log into https://cloud.google.com/console#/project

Select your Project Name, then go into API's & Auth > APIs

Make sure you have Places API Turned on. This is the only thing that needs to be turned on for Places-API to work. enter image description here

2. Go into Credentials

Click CREATE NEW KEY under Public API Access enter image description here

3. Select BROWSER KEY enter image description here

4. Click Create, Nothing Else

Leave the HTTP Refer box empty.

enter image description here

5. Use the Key Generated here

This key will allow ANY user from any device access to the API via your Developer login. You can try it out here: (Be sure to replace YOUR_KEY_HERE with your generated Key)

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

6. Enjoy

Now you can use that URL above in your Android/iOS device.

Moe
  • 4,744
  • 7
  • 28
  • 37
  • This was it. Step 4 (Leave the HTTP Refer box empty.) worked for me. – Marco Jan 12 '14 at 03:06
  • Although this might feel like a kludgey answer, it is the only option. The Google Places API does not currently support the Android or IOS keys.... SMH You can see the official request at google https://code.google.com/p/gmaps-api-issues/issues/detail?id=4896 – Tom Gerken Aug 26 '14 at 21:41
  • Getting "This service requires an API key." this error ios . i am making POST request with Browser key.. please help me. – Avijit Nagare Oct 04 '15 at 07:15
  • @AvijitNagare - start again from the start. You have missed a step or you have not put your API key correctly into the URL in step 5. – Moe Oct 05 '15 at 14:14
4

Try using the BROWSER app key, not the iOS key. You can find it here:

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

And press "API Access" on the left

  • I was trying to use a key for Android app but as @CaptainQuality said, using browser app key worked for me and don't create your mobile OS specific key. I am not sure why this needs to be so confusing from Google. – Rajaraman Subramanian Mar 25 '14 at 12:15
2

The Static Maps API and the Places API each need to be enabled in the API Console for that key. Open the API console and enable access to the Places API. There is a Courtesy limit: 1,000 requests/day, after that you might need to enable billing.

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

geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • Hi, How to enable access to the Places API in the console. Can u brief me the steps. – Dave Dec 26 '13 at 11:36
0

I end up with this code.

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];

    });
});
Avijit Nagare
  • 8,482
  • 7
  • 39
  • 68