1

I am using Google Places API for my iOS application.I have enabled Google Maps Android API v2, Places API from API Console.Create an iOS key in API access section. I am making a request to the Google Places API, using the following code:

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

But I am getting following in JSON Response

{
    "debug_info" =     (
    );
    "html_attributions" =     (
    );
    results =     (
    );
    status = "REQUEST_DENIED";
}

I have regenerated the new key which is not working as well. Can someone please figure out what I am doing wrong here.

Rana Asif
  • 33
  • 1
  • 7
  • Is the specific project enabled in the API console? – Stavash Jul 17 '13 at 06:50
  • Have a look at this. [link](http://stackoverflow.com/questions/9060563/google-places-api-request-denied) – Dunes Buggy Jul 17 '13 at 06:57
  • Also If you want restaurants, you better use types=restaurant rather than the keyword. These two are different in their own ways. – Dunes Buggy Jul 17 '13 at 06:59
  • @Stavash I have just created a project in API Console and genereated iOS key with the bundle identifier of my project.Do I need to do anything else? How could I know whether the specific project is enabled or not.I ll appreciate any help.. I am kinda stuck since 3 hours – Rana Asif Jul 17 '13 at 07:35
  • http://stackoverflow.com/questions/8833085/request-denied-in-responce-of-google-places-api-request-sensor-true – Stavash Jul 17 '13 at 08:06
  • I have enabled Places API in the API Console but still no luck :( – Rana Asif Jul 17 '13 at 09:43

2 Answers2

5

"...The Google Places API does not currently support iOS keys generated from the Google APIs Console. Only Server and Browser keys are currently supported.."

...if you would like to request this support, please file a Places API - Feature Request.."

from this answer: https://stackoverflow.com/a/14744513/1702413

You can use Google Maps JavaScript API v3 (Places Library of the Google Maps API v3)

or..

is working from iOS.. if you are using an HTML5 mobile application framework like Sencha Touch.. you can check this tutorial Create a Location-Aware Site with Sencha Touch

UPD

is working if you are using Key for browser apps (with referers) from API console

for example (I'm using 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];
Community
  • 1
  • 1
TonyMkenu
  • 7,597
  • 3
  • 27
  • 49
  • Then how could I fetch the near by places in iOS application with all details like address, rating,contact number, icon etc?? – Rana Asif Jul 18 '13 at 10:05
  • just tried... is working if you are using "Key for browser apps (with referers)" – TonyMkenu Jul 18 '13 at 11:42
  • this is working well, too... https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&sensor=true&key=browserkey – TonyMkenu Jul 18 '13 at 11:58
  • don't try to call google server from your app directly since server key will be leaked easily. – chings228 Jan 31 '14 at 11:06
  • @chings228 Really? :) What can anything else do with this "public key"? :) What is your method to "call" a google server? – TonyMkenu Jan 31 '14 at 11:28
  • @TonyMkenu there is a limitation for using google api and for particular service , the limit is low, such as elevation api , only 1000 per day. if your key has been hacked, and someone use more that limit all the time , google will block the services not one day only. So the server key must be protected and that's why it call server key. So you should pass the search to your own server and call google from you own server. – chings228 Jan 31 '14 at 12:05
  • @chings228 believe me, I know that... so this key can be stolen ... for what? – TonyMkenu Jan 31 '14 at 12:09
  • @chings228 Worth all this effort for 1000 requests in a day? From you server ... to call google... you must use "Nuclear Power Plant KEY"... so this server key "will be leaked easily", also. Where is the difference? If your key is stolen... you can easily change it - anytime! – TonyMkenu Jan 31 '14 at 12:28
1

This is very easy to get Google Places API key:

Where you create "Android / iOS" keys, there is a more button for creating Browser key.

Simply press "Create new Browser Key" and click on "Create" button.

"BUT Leave the body empty"

For more details similar question, @Moe explaind the complete flow with screenshots.

Community
  • 1
  • 1
Arsalan
  • 513
  • 1
  • 7
  • 22