MAUI - 如何检测 Google 地图上图钉的双击?

问题描述 投票:0回答:1

我想检测 Google 地图上图钉上的双击事件。我目前检测到这样的单击:

foreach (var pin in map.Pins)
{
    pin.MarkerClicked -= MapListPage_MarkerClicked;
    pin.MarkerClicked += MapListPage_MarkerClicked;

}

我尝试查看docs,但找不到任何内容。有没有办法检测 Google 地图图钉上的双击事件?

c# google-maps maui
1个回答
0
投票

我会为点击设置事件处理,并实现一个逻辑来区分双击和单次点击。

我确信以下方面可以改进,但看看这个例子:

private DateTime _lastTapTime = DateTime.MinValue;
private const int DoubleTapThreshold = 300; // Adjust as needed

private void OnPinClicked(object sender, EventArgs e)
{
    var currentTapTime = DateTime.UtcNow;
    var timeDifference = currentTapTime - _lastTapTime;

    if (timeDifference.TotalMilliseconds <= DoubleTapThreshold)
    {
        // A double tap has been detected - do something with it
        OnPinDoubleTapped(sender as Pin);
    }

    _lastTapTime = currentTapTime;
}
private void OnPinDoubleTapped(Pin pin)
{
    // Your double-tap logic here
}
© www.soinside.com 2019 - 2024. All rights reserved.