我正试图在地图上的地图标记中添加一个点击侦听器,以显示信息泡,以便在我的Flutter应用程序中显示关于该位置的详细信息。我试图在这里使用地图、地图和选项,但我似乎不能将点击手势与创建小部件引脚结合起来。我看到JavaScript SDK有一个功能来添加信息泡来映射标记。除了地图针之外,有没有其他方法可以在颤振中实现呢?
这是我编写的一个for循环,用于遍历地图上的Map标记列表,为每个标记创建Widget pin:
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);
});
}发布于 2022-06-20 08:33:17
您不应该为每个标记多次创建一个点击侦听器。相反,只创建一个点击侦听器。然后选择一个带有_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.
});
}有关更多上下文,请参见此示例应用程序:https://github.com/heremaps/here-sdk-examples/blob/d07e4af93b2db946a1f97fdc12cfd6f4b0a760fc/examples/latest/navigate/flutter/map_items_app/lib/MapItemsExample.dart#L306
https://stackoverflow.com/questions/72659461
复制相似问题