ios - 未调用 didTapMyLocationButtonForMapView

标签 ios swift google-maps

我已经实现了 GMSMapViewDelegate 的三个方法,其中两个(markerInfoWindowwillMove)在 时按预期被调用当我点击“我的位置”按钮时,didTapMyLocationButtonForMapView 从未被触发。

初始化:

class MapViewController: UIViewController {
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        GMSServices.provideAPIKey("KEY")
        mapView = GMSMapView(frame: view.frame)
        mapView.settings.myLocationButton = true
        mapView.padding = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        mapView.isMyLocationEnabled = true
        mapView.delegate = self
        view.insertSubview(mapView, at: 0)
    }
}

委托(delegate)实现:

extension MapViewController: GMSMapViewDelegate {
    func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
        ...
        return infoView
    }

    func mapView(_ mapView: GMSMapView, willMove gesture: Bool) {
        ...
    }

    func didTapMyLocationButtonForMapView(mapView: GMSMapView!) -> Bool {
        ...
        return false
    }
}

我尝试过:

  • viewDidLoad 中初始化。
  • 更改viewDidAppear 中方法的顺序(例如,在插入 View 后设置委托(delegate))。
  • 将 Storyboard 中的类设置为 GMSMapView 而不是以编程方式添加。

但似乎没有任何帮助。有什么想法吗?

最佳答案

缺少 _

func didTapMyLocationButtonForMapView(_ mapView: GMSMapView!) -> Bool {
    ...
    return false
}

关于ios - 未调用 didTapMyLocationButtonForMapView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48366731/

相关文章:

ios - 关于使用 UINavigationController 在 iOS 应用程序上扭曲后退按钮

ios - 在 iOS 应用程序中显示实时行情数据

ios - 动态添加具有特定文本和坐标的标签

iphone - SBTableAlert 不起作用

objective-c - 如何选择您可以在 NSTextView 中看到的所有文本?

ios - 更改栏样式需要点击屏幕来更改状态栏文本

ios - 使用 Swift 将更多数据传递到 UISearchController

android - OnMarkerDragStart 正在改变标记的原始位置

objective-c - 如何使用 Google Maps API 搜索地点和邮政编码?

ios - 如何添加 ScrollView 作为信息窗口谷歌地图ios