0
votes

I have read dozens of comments about Google Places queries returning Request_Denied yet nothing seems to be informative for my situation. The app is IOS7 and Xcode 5.0.2.

I have an API key for IOS Applications. In the Google Developers Console the application bundle identifier is listed in the credentials page, and Places API is enabled.

Here’s the core of the code:

-(void)queryGooglePlaces: (NSString *)googleType {
    NSString *url = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%@&types=%@&sensor=false&key=%@", currentCenter.latitude, currentCenter.longitude, [NSString stringWithFormat:@"%i",currenDist], googleType, kGOOGLEAPIKEY];

    NSLog(@"And the url string is: %@", url);//caveman debuging

    NSURL *googleRequestURL = [NSURL URLWithString:url];

    dispatch_async(kBgQueue, ^{
        NSData *data = [NSData dataWithContentsOfURL:googleRequestURL];
        [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
    });

}//queryGooglePlaces:googleType

-(void)fetchedData:(NSData *)responseData {
    //this is to parse out the json data
    NSError *error = nil; //create some error handling here
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

    //I'm told the returned results from Google will be an array obtained from the NSDictionary object with the key "results"

    NSArray *places = [json objectForKey:@"results"];

    //display the data to the console for review
    NSLog(@" Google data:\n%@", places);

}//fetchedData:responseData

The effect in the debug output shows that json status = Request Denied

key __NSCFString * @"status" 0x09a37d10 value __NSCFString * @"REQUEST_DENIED" 0x17961870

and here is the log for the url string, And the url string is: https://maps.googleapis.com/maps/api/place/search/json?location=37.787359,-122.408227&radius=996&types=cafe&sensor=false&key=

I have regenerated the API key with no effect.

ANY help would be appreciated!

2

2 Answers

4
votes

Use Browser key for Google Places API, it works fine on iOS apps. I was having similar issue in last two days and solved by using browser key.

Have read on google groups:

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

Hope it helps

0
votes

Google Places API doesn't work with the application bundle identifier method of client identification. You have to create a server key and append the key to the URL that you request, as an argument to the key parameter you have listed in your URL string.