【问题标题】:GoogleMaps old behaviour, when I tap a marker谷歌地图旧行为,当我点击一个标记
【发布时间】:2017-11-30 16:24:17
【问题描述】:

我使用的是 xcode 9.0、GoogleMaps SDK 2.5.0 和 GooglePlaces 2.5.0。

func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool 方法中,当我选择一个标记并返回到仅显示标记且未启用自动中心的旧行为时,我正在尝试禁用自动居中地图。问题是当我实现该行为(已注释的行)时标记没有出现,我搜索的所有堆栈溢出都实现了这些行。我迷路了

class MapViewController: UIViewController, GMSMapViewDelegate
{

    //MARK: Class Life Cycle

    @IBOutlet weak var mapView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        setupUI()
        setupMap()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    //MARK: -Setup

    func setupUI() {
        navigationController?.hideBar()
    }

    func setupMap() {
        let map = MapManager.sharedInstance.setupMap(view: mapView, latitude: GoogleMap.latitude, longitude: GoogleMap.longitude, zoom: GoogleMap.zoom)
        map.delegate = self
        mapView.addSubview(map)

        MapManager.sharedInstance.setupMapMarkers(map: map, file: File.geoFence, fileType: File.json)
    }

    func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
        //        mapView.selectedMarker = marker
        //        return true

        return false
    }
}

【问题讨论】:

    标签: ios swift google-maps marker gmsmapview


    【解决方案1】:

    如果有人遇到这个奇怪的错误,奇怪的解决方案是再次添加委托:

    func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
        mapView.delegate = self
        mapView.selectedMarker = marker
        return true
    
        return false
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-27
      • 2010-11-06
      • 1970-01-01
      • 1970-01-01
      • 2017-10-20
      • 2011-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多