如何在地图上添加标记

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

我正在使用Flutter SDK 4.3.1.0版本。

我想在地图上显示标记,我发现这将是可能通过。

final String positionMarkerPath = 'assets/markers/marker.png';

mapScene.addMapMarker(
  MapMarker(
    geoCoordinates,
    MapImage.withFilePathAndWidthAndHeight(positionMarkerPath, 32, 32)));

当使用这种方法时,我不断得到错误

E/CL_geoviz( 9632): [ERROR] CL_geoviz - Can't find image 'file:///assets/markers/marker.png' in asset repository.
E/CL_geoviz( 9632): [ERROR] CL_geoviz - Can't load image file 'file:///assets/markers/marker.png' to memory stream.

现在,该方法 MapImage.withFilePathAndWidthAndHeight 在SDK中被记录如下。

Creates a new map image from the provided path to the SVG Tiny image 这很奇怪,因为我认为Flutter甚至不支持SVG的开箱即用。这可能是一个问题吗?或者我在这里做错了什么?

我试过使用SVG、Vector Drawable和png,试过完全限定路径,什么都不行。

flutter here-api
1个回答
1
投票

文档中的 MapImage.withFilePathAndWidthAndHeight 说,这只是为 SVG Tiny 格式。但它目前似乎并不工作,因为Flutter的HERE SDK仍处于Beta状态。

你可以像这样加载和添加PNG文件作为标记。

ByteData data = await rootBundle.load('assets/some_image.png');
MapImage image = MapImage.withPixelDataAndImageFormat(Uint8List.view(data.buffer), ImageFormat.png);
MapMarker marker = MapMarker(geoCoordinates, image);
hereMapController.mapScene.addMapMarker(marker);

资产目录需要在 pubspec.yaml.

© www.soinside.com 2019 - 2024. All rights reserved.