Google Places iOS - Can't load search result

2020-02-12 13:15发布

问题:

I am using GMSAutoCompleteViewController from Google Places API in my iOS Project.

Suddenly today my GMSAutoCompleteViewController keeps on giving me error "Can't load Search Results".

I have regenerated my API Key using fresh one. I have tried everything, but still some how it does not work.

I am using Objective-C. Can anyone help ?

Code

GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
    acController.delegate = self;
[self.navigationController pushViewController:acController animated:YES];

Delegate Methods

- (void)viewController:(GMSAutocompleteViewController *)viewController
                didAutocompleteWithPlace:(GMSPlace *)place {
    // Do something with the selected place.
    NSLog(@"Place name %@", place.name);
    NSLog(@"Place address %@", place.formattedAddress);
    NSLog(@"Place attributions %@", place.attributions.string);
    NSLog(@"Latitude = %.20f",place.coordinate.latitude);
    NSLog(@"Longitude = %.20f",place.coordinate.longitude);
    NSLog(@"Type = %@",place.types);
    NSLog(@"Place ID = %@",place.placeID);
    //[self dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];

    /* Call and API in background to get the address according to the new LAT AND LONG as well
     Once get the address from there we can store the latitude and longitude in the cache
     if type of search is Postal code then we have to call another web service i.e. FIND ADDRESS to get the whole exact address */

    [self callWS_ConvertLatLongWithLatitude:[NSString stringWithFormat:@"%.20f",place.coordinate.latitude]
                               andLongitude:[NSString stringWithFormat:@"%.20f",place.coordinate.longitude]
                               inBackground:NO];

}

- (void)viewController:(GMSAutocompleteViewController *)viewController
didFailAutocompleteWithError:(NSError *)error {

    NSLog(@"error: %ld", [error code]);

    [self.navigationController popViewControllerAnimated:YES];

}

// User canceled the operation.
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
    NSLog(@"Autocomplete was cancelled.");

    [self.navigationController popViewControllerAnimated:YES];
}

// Turn the network activity indicator on and off again.
- (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

- (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

回答1:

Makesure Google Places API for IOS is enabled.

  1. Go to your https://console.developers.google.com/apis/
  2. Choose "Library" - "Google Places API for iOS"
  3. ENABLE (Blue Button)

API Key as same as Google Maps APIKey



回答2:

After 18th June 2018 , google have restrict the limit and changed the policy,you need to enable billing after then it will be work.

I was already enabled the google places api and google map api but still it was showing the error .

After enable the billing its resolved



回答3:

I faced the same issue. When i went back and checked the billing account page again i noticed that it has doesn't have my current working project name listed . Once i added my current project , it worked.

Make sure your current project is listed in the billing page



回答4:

-> Make sure to Update to latest version of the Google Places Pod (GooglePlacepicker is Deprecated)

-> Enable API of Google Places

-> Also Check APIKey is Proper