如何使用 GMSPlacePickerViewController class?
How to use GMSPlacePickerViewController class?
我按如下方式创建了选择器:
let placePicker = GSMPlacePickerViewController(config: config)
placePicker.delegate?.placePicker(viewController: GSMPlacePickerViewController, didPick: GSMPlace)
在上面代码的第二行中,我如何将用户选择的位置存储在我自己的变量中,以便稍后我可以像访问坐标一样访问它的 properties?
我对如何实现 GSMPlacePickerViewController
方法感到困惑,无法在线找到示例。
从GSMPlacePickerViewController
docs开始,它说我不必实现第一个参数,如果我理解正确,我可以将其留空
Implementations of this method should dismiss the view controller as
the view controller will not dismiss itself.
所以我现在的问题是将用户选择的位置存储在我自己的变量中。
我该如何实现?
将 GMSPlacePickerViewControllerDelegate 添加到您的视图控制器,如下所示:
class YourViewController: GMSPlacePickerViewControllerDelegate {
}
然后在上述 VC 中添加委托方法,当用户选择位置时将调用该委托方法。然后,您可以关闭并访问地点数据,如下所示:
func placePicker(_ viewController: GMSPlacePickerViewController, didPick place: GMSPlace) {
placePicker.dismiss(animated: true, completion: nil)
let location = CLLocation(latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
}
我按如下方式创建了选择器:
let placePicker = GSMPlacePickerViewController(config: config)
placePicker.delegate?.placePicker(viewController: GSMPlacePickerViewController, didPick: GSMPlace)
在上面代码的第二行中,我如何将用户选择的位置存储在我自己的变量中,以便稍后我可以像访问坐标一样访问它的 properties?
我对如何实现 GSMPlacePickerViewController
方法感到困惑,无法在线找到示例。
从GSMPlacePickerViewController
docs开始,它说我不必实现第一个参数,如果我理解正确,我可以将其留空
Implementations of this method should dismiss the view controller as the view controller will not dismiss itself.
所以我现在的问题是将用户选择的位置存储在我自己的变量中。
我该如何实现?
将 GMSPlacePickerViewControllerDelegate 添加到您的视图控制器,如下所示:
class YourViewController: GMSPlacePickerViewControllerDelegate {
}
然后在上述 VC 中添加委托方法,当用户选择位置时将调用该委托方法。然后,您可以关闭并访问地点数据,如下所示:
func placePicker(_ viewController: GMSPlacePickerViewController, didPick place: GMSPlace) {
placePicker.dismiss(animated: true, completion: nil)
let location = CLLocation(latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
}