Google map API 有一个 didTapInfoWindowOf
方法,可以检测何时点击标记的信息窗口。
我试图将此事件限制为在一段时间内仅点击一次。
当我点击信息窗口时,我正在对后端服务器进行 api 调用,当我收到响应时,我会转到不同的 View 。问题是用户可以多次点击此信息窗口,从而多次触发 api 调用。
有没有办法限制这个?
目前,我正在使用本地定义的属性 didTapWindowCount
并限制每次点击时的 api 调用,如下所示:
var didTapInfoWindowCount = 0
func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {
didTapInfoWindowCount += 1
// perform api call -- limit to once until done
if didTapInfoWindowCount == 1 {
myAPICall {
// on success
didTapInfoWindowCount = 0
}
}
}
我想知道是否有解决方法或者 API 中是否内置了某些内容?
最佳答案
mapView(_ mapView: GMSMapView, didTapInfoWindowOfmarker: GMSMarker)
将在用户点击 marker< 的
.info window
时被调用多次
为了避免在 API 命中时多次调用它,您可以使用 Bool
值。
var didTapInfoWindow = false
func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker)
{
if !didTapInfoWindow
{
didTapInfoWindow = true
myAPICall {
// on success
didTapInfoWindow = false
}
}
}
关于iOS:Google Maps API - 禁用信息窗口点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44311788/