在这里地图点击侦听器以显示flutter中的信息泡泡

发布于 2025-02-08 09:00:02 字数 775 浏览 0 评论 0原文

我正在尝试在地图上的地图标记中添加点击侦听器以显示 info-bubble 以在我的 flutter中显示有关该位置的详细信息应用程序。我试图在此处使用 MAP MAP PIN 选项,但我似乎无法将tap手势与创建窗口小部件的销钉结合在一起。我看到JavaScript SDK具有将Info-Bubble添加到映射标记的功能。除了地图引脚外,有没有办法在颤音中做到这一点?

这是我写的循环循环浏览地图上的地图标记列表,为它们创建了小部件引脚:


     for (var a = 0; a < _mapMarkerList.length; a++) {
          _hereMapController.gestures.tapListener =
              TapListener((Point2D touchPoint) {
            _hereMapController.viewToGeoCoordinates(touchPoint);
            _hereMapController.pinWidget(
                _createWidget('Here is my label', Color(0xFFFCAE06)),
                _mapMarkerList.elementAt(a).coordinates);
          });
        }

I'm trying to add a tap listener to my map markers on my map to show an info-bubble to show details about that location in my Flutter app. I tried to use the Here Maps Map Pin option but I can't seem to combine on-tap gestures with creating a widget pin. I saw that the JavaScript SDK has a function to add info-bubble to map markers. Is there a way to do that in Flutter apart from the Map Pins?

This is a for loop I wrote to go through the list of Map markers on the map to create the Widget pin for each of them :


     for (var a = 0; a < _mapMarkerList.length; a++) {
          _hereMapController.gestures.tapListener =
              TapListener((Point2D touchPoint) {
            _hereMapController.viewToGeoCoordinates(touchPoint);
            _hereMapController.pinWidget(
                _createWidget('Here is my label', Color(0xFFFCAE06)),
                _mapMarkerList.elementAt(a).coordinates);
          });
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人生戏 2025-02-15 09:00:02

您不应该为每个标记创建多次点击侦听器。而是仅创建一个点击侦听器。然后选择_HEREMAPCONTROLLER.PICKMAPITEMS()的标记。在回调内部,您可以创建一个地图视图引脚。

  void _setTapGestureHandler() {
    _hereMapController.gestures.tapListener = TapListener((Point2D touchPoint) {
      _pickMapMarker(touchPoint);
    });
  }

  void _pickMapMarker(Point2D touchPoint) {
    double radiusInPixel = 2;
    _hereMapController.pickMapItems(touchPoint, radiusInPixel, (pickMapItemsResult) {
      if (pickMapItemsResult == null) {
        // Pick operation failed.
        return;
      }    

      List<MapMarker> mapMarkerList = pickMapItemsResult.markers;
      int listLength = mapMarkerList.length;
      if (listLength == 0) {
        print("No map markers found.");
        return;
      }

      MapMarker topmostMapMarker = mapMarkerList.first;
      // Now create a map view pin based on this marker's coordinates.
    });
  }

See this example app for more context:

You should not create a tap listener multiple times for each marker. Instead create only one tap listener. And then pick a marker with _hereMapController.pickMapItems(). Inside the callback you can create a map view pin.

  void _setTapGestureHandler() {
    _hereMapController.gestures.tapListener = TapListener((Point2D touchPoint) {
      _pickMapMarker(touchPoint);
    });
  }

  void _pickMapMarker(Point2D touchPoint) {
    double radiusInPixel = 2;
    _hereMapController.pickMapItems(touchPoint, radiusInPixel, (pickMapItemsResult) {
      if (pickMapItemsResult == null) {
        // Pick operation failed.
        return;
      }    

      List<MapMarker> mapMarkerList = pickMapItemsResult.markers;
      int listLength = mapMarkerList.length;
      if (listLength == 0) {
        print("No map markers found.");
        return;
      }

      MapMarker topmostMapMarker = mapMarkerList.first;
      // Now create a map view pin based on this marker's coordinates.
    });
  }

See this example app for more context: https://github.com/heremaps/here-sdk-examples/blob/d07e4af93b2db946a1f97fdc12cfd6f4b0a760fc/examples/latest/navigate/flutter/map_items_app/lib/MapItemsExample.dart#L306

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文