0

Image of my screen I want to show a map with place picker. I create needed APIs and I added them in my AppDelegate.m. Then I implemented this code in my view controller:

 - (void)location
{
    GMSPlacePickerConfig *config = [[GMSPlacePickerConfig alloc] initWithViewport:nil];
    GMSPlacePickerViewController *placePicker = [[GMSPlacePickerViewController alloc] initWithConfig:config];
    placePicker.delegate = self;
    [self presentViewController:placePicker animated:YES completion:nil];
}

- (void)placePicker:(GMSPlacePickerViewController *)viewController didPickPlace:(GMSPlace *)place {
    [viewController dismissViewControllerAnimated:YES completion:nil];

    NSLog(@"Place name %@", place.name);
    NSLog(@"Place address %@", place.formattedAddress);
    NSLog(@"Place attributions %@", place.attributions.string);
}

- (void)placePickerDidCancel:(GMSPlacePickerViewController *)viewController {
    [viewController dismissViewControllerAnimated:YES completion:nil];

    NSLog(@"No place selected");
}

I get GMSPlacePickerViewController but without map under my pins. Any ideas?

Justyna J
  • 1
  • 2

1 Answers1

0

When you initiliaze placePickerConfig with viewport: nil it defaults to the user's current location. Make sure you have the user's location before doing all this. Test the map out by providing constant map coordinates when initiliazing GMSPlacePickerConfig like this:

let center = CLLocationCoordinate2DMake(-33.86, 151.20)
let northEast = CLLocationCoordinate2DMake(center.latitude + 0.001, center.longitude + 0.001)
let southWest = CLLocationCoordinate2DMake(center.latitude - 0.001, center.longitude - 0.001)
let viewport = GMSCoordinateBounds(coordinate: northEast, coordinate: southWest)

then initilializing placePickerConfig with the viewport. I used swift as I don't know obj-c but you can easily convert it. If this turns out to be the problem you need to get the user's coordinates first

Marij Khan
  • 151
  • 1
  • 12