swift - 适用于 ios 的 google placepicker 和 BackgroundMapViewController.swift

标签 swift google-maps

我正在尝试为 ios 实现 google 的 placepicker。 有一些演示代码:

https://github.com/googlemaps/maps-sdk-for-ios-samples/tree/master/GooglePlacePicker/GooglePlacePickerDemos

除了文件 PickAPlaceViewController.swift 中的行之外,我得到了大部分内容

  var mapViewController: BackgroundMapViewController?

在 github 存储库中,Google 提供了自己的类 BackgroundMapViewController。

我需要创建此类的实例才能使用地点选择器吗?

或者我可以像平常使用谷歌地图一样使用 GMSMapView 吗?

谢谢。

最佳答案

对于 Google 地点 Controller ,您只需要以下代码即可在您的应用中显示或呈现地点 Controller 。

将其放入您的按钮操作方法中:

// Create a place picker. Attempt to display it as a popover if we are on a device which
    // supports popovers.
    let config = GMSPlacePickerConfig(viewport: nil)
    let placePicker = GMSPlacePickerViewController(config: config)
    placePicker.delegate = self
    placePicker.modalPresentationStyle = .popover
    placePicker.popoverPresentationController?.sourceView = pickAPlaceButton
    placePicker.popoverPresentationController?.sourceRect = pickAPlaceButton.bounds

    // Display the place picker. This will call the delegate methods defined below when the user
    // has made a selection.
    self.present(placePicker, animated: true, completion: nil)

希望这将有助于在您的应用中显示地点选择器。

关于swift - 适用于 ios 的 google placepicker 和 BackgroundMapViewController.swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46037000/

相关文章:

swift - 为什么 TouchBegan 不能正常工作?

android - Google map android 中的一组纬度和经度点的中心

android - 防止 Google SupportMapFragment 重新加载

ios - 由于 API key 无效(格式错误或丢失),操作失败

ios - 如何获取iOS项目中项目文件的路径?

swift - 闭包内的完成闭包

swift - GK状态 : Why is StateMachine == nil on delegate call?

swift - 小导航标题显示几秒钟

api - google maps api 响应错误消息 "Resource interpreted as Image but transferred with MIME type text/html"

javascript - 使用 Javascript,我如何随机偏移经度和纬度数字