ios - 如何使用 swift 在 iOS 中点击谷歌地图来放置标记

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

如何使用 swift 在 iOS 中点击谷歌地图来放置标记?代码如下:

func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) 
{   
    let markerr = GMSMarker(position: coordinate)
    markerr.position.latitude = coordinate.latitude
    markerr.position.longitude = coordinate.longitude
    print("hello")
    print(markerr.position.latitude)
    let ULlocation = markerr.position.latitude
    let ULlgocation = markerr.position.longitude
    print(ULlocation)
    print(ULlgocation)
    markerr.map = self.googleMapsView
    mapView.delegate = self
 }

最佳答案

func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
    mapView.clear()
    DispatchQueue.main.async {
        let position = CLLocationCoordinate2D(latitude: coordinate.latitude, longitude: coordinate.longitude)
        self.marker.position = position
        self.marker.map = mapView
        self.marker.icon = UIImage(named: "default_marker")
        print("New Marker Lat Long - ",coordinate.latitude, coordinate.longitude)
    }
}

关于ios - 如何使用 swift 在 iOS 中点击谷歌地图来放置标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48416965/

相关文章:

iOS 加载 16bit 单 channel 图像

javascript - 防止在带有 Canvas 的页面上的移动设备上滚动

mysql - Json feed blob 图像在 UIImage swift 中显示

javascript - Google map API - 将鼠标悬停在标记上并显示图像

javascript - 如何隐藏/显示 Google map 折线符号

ios - SKLabelNode 文本消失使用 iOS 7.1

ios - 使用CABasicAnimation切割 View 一半

ios - Swift - 如何将点击手势添加到 UIViews 数组?

swift - 检查字符串类型数组中的空格 - Swift

javascript - 嵌入式 Google map 图 block 在缩放之前无法在 Firefox 第二页加载中加载