ios - 当用户在 google maps swift 中触摸屏幕时放下别针

标签 ios swift google-maps google-maps-markers

我想在 Google map 中添加和删除 Marker(pin)。

我想通过长按放下图钉并将其移除。我想用它来选择我的目的地。我该怎么做?

let  position = CLLocationCoordinate2DMake(10, 10)
let marker = GMSMarker(position: position)
marker.map = mapView

最佳答案

对于正在寻找使用 Swift 的完整代码片段的人:

  1. 实现协议(protocol)GMSMapViewDelegate
  2. 拖动 GMSMapView 的一个实例 @IBOutlet weak var googleMapView: GMSMapView!
  3. viewDidLoad() 中提及 GMSMapView Delegate 作为 googleMapView.delegate = self
  4. 实现 didTapAt 委托(delegate)函数:

func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D){ print("你点击了\(coordinate.latitude),\(coordinate.longitude)") googleMapView.clear()//在添加新 Pin 之前清除 Pin 让标记= GMSMarker(位置:坐标) marker.map = googleMapView }

关于ios - 当用户在 google maps swift 中触摸屏幕时放下别针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37680199/

相关文章:

ios - GStreamer-无法构建管道: no element tcppclientsrc

swift - swift 将 UTC 日期转换为本地日期

javascript - 如何在 map 上创建一个覆盖标记,它保持在 react-native 的屏幕中心

ios - 使用 UIActivityViewController 在 Swift 3 中的 WhatsApp 上共享实时照片不起作用

ios - 如何在相册上选择图像 - iOS 测试 KIF

ios - Spotify 返回无效的 NSDictionary

android - 在 android 的 Ionic 项目中的位置

ios - 自定义应用程序中的 UITableview 部分

Swift:无法捕获具有关联数据的特定错误情况

javascript - 如何使用 javascript 根据一组纬度和经度值计算面积?