Reputation: 333
I created the picker as follows:
let placePicker = GSMPlacePickerViewController(config: config)
placePicker.delegate?.placePicker(viewController: GSMPlacePickerViewController, didPick: GSMPlace)
In the second line of the code above, how can I store the place the user picks inside a variable of my own so later I can access its properties like the coordinates?
I am confused on how to implement GSMPlacePickerViewController
method and couldn't find examples online.
As from the GSMPlacePickerViewController
docs, it says that I don't have to implement the first parameter and I could leave it empty if I understood it correctly
Implementations of this method should dismiss the view controller as the view controller will not dismiss itself.
So my problem now, is storing the user selected location in a variable of my own.
How should I go to achieving that?
Upvotes: 1
Views: 633
Reputation: 1484
Add GMSPlacePickerViewControllerDelegate to your view controller like so:
class YourViewController: GMSPlacePickerViewControllerDelegate {
}
Then add the delegate method within said VC which will be called when the user picks the place. You then dismiss and access place data like below:
func placePicker(_ viewController: GMSPlacePickerViewController, didPick place: GMSPlace) {
placePicker.dismiss(animated: true, completion: nil)
let location = CLLocation(latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
}
Upvotes: 1