【问题标题】:Is there a way to Fix a Google Maps Marker to the Center of its Map always in iOS using swift?有没有办法在 iOS 中使用 swift 将 Google Maps Marker 固定到其地图的中心?
【发布时间】:2019-08-26 17:44:07
【问题描述】:

我想要的是我想将标记位置固定到我的地图视图的中心。当地图仍然移动时,我的标记应该粘在那个中心点上。 标记代码如下:

var pin:GMSMarker = GMSMarker(position: CLLocationCoordinate2DMake(currentLocation.coordinate.latitude, currentLocation.coordinate.longitude))
pin.icon = UIImage(named: "img_map_pin")
pin.map = mapView?
pin.infoWindowAnchor = CGPointMake(0.44, 0.44)
mapView?.selectedMarker = pin

我想和 Uber 一样。当地图移动标记位于中心并且地图停止移动后,我从地图中获取该点的地址。

【问题讨论】:

    标签: ios google-maps swift


    【解决方案1】:

    GMSMapViewDelegate 分配给class 并添加以下代码

     func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
         pin.position = position.target
     }
    

    【讨论】:

      猜你喜欢
      • 2013-10-20
      • 2018-12-22
      • 1970-01-01
      • 2012-07-02
      • 1970-01-01
      • 2012-01-29
      • 2019-06-10
      • 2018-08-01
      • 2016-05-04
      相关资源
      最近更新 更多