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 :
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 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")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With