0

This error is crashing the app while trying to use GMSPlacePicker in objC

'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]'

The app is crashed at the point [placePicker pickPlaceWithCallback:^(GMSPlace * _Nullable place, NSError * _Nullable error)

The whole set code block is below:

    CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(22.631514, 51.4723);
    CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(26.0765, 56.4395);
    GMSCoordinateBounds *viewport = [[GMSCoordinateBounds alloc] initWithCoordinate:northEast coordinate:southWest];
    GMSPlacePickerConfig *config = [[GMSPlacePickerConfig alloc] initWithViewport:viewport];
    GMSPlacePicker *placePicker = [[GMSPlacePicker alloc] initWithConfig:config];
    [placePicker pickPlaceWithCallback:^(GMSPlace * _Nullable place, NSError * _Nullable error)
    {
        if (error!= NULL && error != nil) {
            NSLog(@"PlacePicker error: %@", [error localizedDescription]);  
            return;
        }
         if (place != NULL && place != nil) {
            NSLog(@"PlacePicker cordinates: (%f, %f)", place.coordinate.latitude, place.coordinate.longitude);
         } else {
            NSLog(@"No place selected");
         }
    }];

Please help.

Rince Thomas
  • 4,158
  • 5
  • 25
  • 44
Asha Antony
  • 441
  • 5
  • 8
  • at which line your code broken ? – KKRocks May 08 '17 at 06:00
  • At this point [placePicker pickPlaceWithCallback:^(GMSPlace * _Nullable place, NSError * _Nullable error) – Asha Antony May 08 '17 at 06:02
  • did you provide key for these in appdelegate : GMSServices.provideAPIKey("Your key") GMSPlacesClient.provideAPIKey("Your key") ? – KKRocks May 08 '17 at 06:06
  • Yes I did. The code was working before... But now it is crashing. – Asha Antony May 08 '17 at 06:08
  • what the os version ? – KKRocks May 08 '17 at 06:09
  • iOS version is 10.3.1 and XCode Version 8.3.1 – Asha Antony May 08 '17 at 06:10
  • try to make GMSPlacePicker property instead of local variable. – KKRocks May 08 '17 at 06:10
  • assuming that your bundle identifier is as same as what you have configured to get api key. A change should be made not sure if it is related to this error, but instead of `(error!= NULL && error != nil)` it should be `(error!= NULL || error != nil)` – Priyal May 08 '17 at 06:12
  • I tried @property(nonatomic, strong) GMSPlacePicker *placePicker; and (error!= NULL || error != nil). But the still the same crash – Asha Antony May 08 '17 at 06:14
  • Probably Place information could be nil. try by commenting following code if (place != NULL && place != nil) { NSLog(@"PlacePicker cordinates: (%f, %f)", place.coordinate.latitude, place.coordinate.longitude); } else { NSLog(@"No place selected"); } – Avijit Nagare May 08 '17 at 07:49
  • i tried with empty block too.. still it's crashing at the block start. – Asha Antony May 08 '17 at 07:51
  • I updated the GooglePlacePicker Pods, now they are using GMSPlacePickerViewController and delegate methods instead of GMSPlacePicker. So far working fine. No crash. – Asha Antony Jul 20 '17 at 05:31
  • @AshaAntony can you put sample code here, how it has worked for you.. here is my question i have asked today.. i am facing issue while doing this same feature. https://stackoverflow.com/questions/49856173/i-want-to-display-google-place-picker-for-restaurants-using-gmsplacepickerviewco?noredirect=1#comment86729791_49856173 – Maheta Dhaval K Apr 16 '18 at 12:56

0 Answers0