A delegate has not been set on an instance of GMSPlacePickerViewController before us

Multi tool use
A delegate has not been set on an instance of GMSPlacePickerViewController before us
I've been playing around for couple days with IOS and Google Maps Api and two days ago the API was upgraded to the version 2.3 which deprecate the use of GMSPlacePicker.
Deprecation notice: GMSPlacePicker
Notice: The implementation of the place picker has changed. As of version 2.3 of the Google Places API for iOS, the GMSPlacePicker class is deprecated, replaced by GMSPlacePickerViewController. Use of the GMSPlacePicker class will only be supported until May 1, 2018. We recommend that you update your code to use GMSPlacePickerViewController when possible.
In my code I switched to GMSPlacePickerViewController
however I still get an error on the logs saying :
GMSPlacePickerViewController
Places API warning: A delegate has not been set on an instance of GMSPlacePickerViewController before use. Note that this may result in undefined behavior such as being unable to dismiss screens, not being notified of selections, and being unable to correctly manage object lifecycle.
Even though my class is extending the delegate
class ReportController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource,GMSPlacePickerViewControllerDelegate{
// code goes here
}
Any idea how to solve this ?
I was missing to link the delegate to the controller. Try adding
placepicker.delegate = self
– 113408
Jun 27 '17 at 0:12
placepicker.delegate = self
I almost kept using the deprecated GMSPlacePicker because of that... and it was so obvious. Thanks for letting me know. It wasn't in the documentation though but still obvious :D
– Edouard Barbier
Jun 27 '17 at 0:47
2 Answers
2
I had also the same problem I resolved this by using this code.
Here is the code .
let config = GMSPlacePickerConfig(viewport: nil)
let placePicker = GMSPlacePickerViewController(config: config)
placePicker.delegate = self
present(placePicker, animated: true, completion: nil)
Hope this will also resolve your problem
GoogleMap version 2.3
The document also make me feel confuse in version 2.3
The picture below is a picture that I crop from the google document.
This link is a document from google map SDK for this Solution
you just write the code according to document and add a one line of code below the code was accentuated by the red pen.
The code that I wrote accordingly from document below here
// The code snippet below shows how to create and display a GMSPlacePickerViewController.
@IBAction func pickPlace(_ sender: UIButton) {
let config = GMSPlacePickerConfig(viewport: nil)
let placePicker = GMSPlacePickerViewController(config: config)
placePicker.delegate = self
present(placePicker, animated: true, completion: nil)
}
// To receive the results from the place picker 'self' will need to conform to
// GMSPlacePickerViewControllerDelegate and implement this code.
func placePicker(_ viewController: GMSPlacePickerViewController, didPick place: GMSPlace) {
// Dismiss the place picker, as it cannot dismiss itself.
viewController.dismiss(animated: true, completion: nil)
print("Place name (place.name)")
print("Place address (String(describing: place.formattedAddress))")
print("Place attributions (String(describing: place.attributions))")
}
func placePickerDidCancel(_ viewController: GMSPlacePickerViewController) {
// Dismiss the place picker, as it cannot dismiss itself.
viewController.dismiss(animated: true, completion: nil)
print("No place selected")
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I'm currently facing the same issue. Did you find a solution in the end?
– Edouard Barbier
Jun 27 '17 at 0:06