gpt4 book ai didi

iOS Swift 谷歌地图 - mapView didTapMarker 不工作?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:25:01 28 4
gpt4 key购买 nike

所以我正在学习并了解 swift/google maps API。但是,无论我尝试什么,当我点击标记时,我无法让打印语句出现在控制台中。

点击标记会显示标记名称,但不会打印出来。我已经尝试了一些在网上找到的私有(private)函数的变体,但也许我在这里遗漏了一些更基本的东西......

import UIKit
import GoogleMaps

class ViewController: UIViewController, GMSMapViewDelegate {

override func viewDidLoad() {
super.viewDidLoad()

struct MarkerStruct {
let name: String
let lat: CLLocationDegrees
let long: CLLocationDegrees
}

let markers = [
MarkerStruct(name: "Food Hut 1", lat: 52.649030, long: 1.174155),
MarkerStruct(name: "Foot Hut 2", lat: 52.649030, long: 1.174185),
]

let camera = GMSCameraPosition.camera(withLatitude: 52.649030, longitude: 1.174155, zoom: 14)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
mapView.delegate = self
self.view = mapView

for marker in markers {
let position = CLLocationCoordinate2D(latitude: marker.lat, longitude: marker.long)
let locationmarker = GMSMarker(position: position)
locationmarker.title = marker.name
locationmarker.map = mapView
}
}

private func mapView(mapView: GMSMapView, didTapMarker marker: GMSMarker) {
print("Marker tapped")
}

}

最佳答案

您使用的是旧方法名称,您还需要删除 private 关键字,这就是不调用您的委托(delegate)方法的原因

现在是

func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
print("Marker tapped")
return true
}

现在工作

关于iOS Swift 谷歌地图 - mapView didTapMarker 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48110987/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com