【发布时间】:2021-07-06 12:37:36
【问题描述】:
基本代码带有一个元数据弹出窗口,但我不知道如何转换它以在弹出窗口中显示来自 API 调用的数据,这些数据与单个地图标记相关,所有这些都通过已经有不同的 API 调用。
Map Marker API 调用在 Json 反馈中包含一个 ID,我需要获取该 ID 并在调用的 URL 中调用一个单独的 API,然后在弹出窗口中显示。
我可以通过call 获取数据并显示为列表 - 我只是在努力将其集成到相关标记的弹出窗口中
标记通过 API 调用很好地放置在地图上,但弹出窗口通过代码中的 string 显示库存元数据
我几乎找不到关于将 API 数据放置在 HERE Map 弹出窗口中的文档,该窗口内置于 Flutter for mobile。
此代码将标记添加到地图,底部的元数据功能
Future<void> _addPOIMapMarker(GeoCoordinates geoCoordinates, int drawOrder) async {
if (_poiMapImage == null) {
Uint8List imagePixelData = await _loadFileAsUint8List('assets/poi.png');
_poiMapImage = MapImage.withPixelDataAndImageFormat(imagePixelData, ImageFormat.png);
}
Anchor2D anchor2D = Anchor2D.withHorizontalAndVertical(0.5, 1);
MapMarker mapMarker = MapMarker.withAnchor(geoCoordinates, _poiMapImage, anchor2D);
mapMarker.drawOrder = drawOrder;
Metadata metadata = new Metadata();
metadata.setString("key_poi", "T");
mapMarker.metadata = metadata;
_hereMapController.mapScene.addMapMarker(mapMarker);
_mapMarkerList.add(mapMarker);
}
Future<void> _addCircleMapMarker(GeoCoordinates geoCoordinates, int drawOrder) async {
if (_circleMapImage == null) {
Uint8List imagePixelData = await _loadFileAsUint8List('assets/circle.png');
_circleMapImage = MapImage.withPixelDataAndImageFormat(imagePixelData, ImageFormat.png);
}
MapMarker mapMarker = MapMarker(geoCoordinates, _circleMapImage);
mapMarker.drawOrder = drawOrder;
_hereMapController.mapScene.addMapMarker(mapMarker);
_mapMarkerList.add(mapMarker);
}
Future<Uint8List> _loadFileAsUint8List(String assetPathToFile) async {
ByteData fileData = await rootBundle.load(assetPathToFile);
return Uint8List.view(fileData.buffer);
}
void _setTapGestureHandler() {
_hereMapController.gestures.tapListener = TapListener.fromLambdas(lambda_onTap: (Point2D touchPoint) {
_pickMapMarker(touchPoint);
});
}
void _pickMapMarker(Point2D touchPoint) {
double radiusInPixel = 2;
_hereMapController.pickMapItems(touchPoint, radiusInPixel, (pickMapItemsResult) {
List<MapMarker> mapMarkerList = pickMapItemsResult.markers;
if (mapMarkerList.length == 0) {
print("No map markers found.");
return;
}
MapMarker topmostMapMarker = mapMarkerList.first;
Metadata metadata = topmostMapMarker.metadata;
if (metadata != null) {
String message = metadata.getString("key_poi") ?? "No message found.";
_showDialog("ND", message);
return;
}
_showDialog("ND", "No metadata attached.");
});
}
在此先感谢
【问题讨论】:
标签: flutter dart mobile maps here-api