1
votes

I am using google places api to get that place's photo but i am unable to locate "photo_reference" field in the returned JSON. Here is what i have done so far.

NSString *urlString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/details/json?placeid=%@&key=%@",placeId,appKey];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"GET"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue new] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
    if (!connectionError) {
        NSLog(@"Got Place Details");
        NSDictionary *details = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
        NSString *photo_reference = [[[[details valueForKey:@"result"] valueForKey:@"photos"] objectAtIndex:0] valueForKey:@"photo_reference"];
        NSLog(@"");
        NSString *urlString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/photo?maxwidth=302&maxheight=275&photoreference=%@&key=%@",photo_reference,appKey];
        NSURL *url = [NSURL URLWithString:urlString];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
        [request setHTTPMethod:@"GET"];
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue new] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            NSLog(@"Inner Request");
            if (!connectionError) {

        }];

    }
}];

Places API documentation says that photo_reference could either be found from "Place Search" or "Place Details" requests. I got it from none. I requested place details using place_id but the json doesnt have any "photos" key.

1

1 Answers

0
votes

Same issue here

https://stackguides.com/questions/28317739/places-api-dont-retrieve-photos-on-detailed-petition-since-yesterday

Something change since yesterday but I don't know what or why.

EDIT: Today it's working again, maybe some random error from google.