如何在地图上添加标记
How to add markers on the map
我正在使用 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,尝试完全限定路径,但没有任何效果
MapImage.withFilePathAndWidthAndHeight
的文档说它仅适用于 SVG Tiny 格式。但它目前似乎无法正常工作,因为 HERE SDK for Flutter 仍处于 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
中指定。
我正在使用 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,尝试完全限定路径,但没有任何效果
MapImage.withFilePathAndWidthAndHeight
的文档说它仅适用于 SVG Tiny 格式。但它目前似乎无法正常工作,因为 HERE SDK for Flutter 仍处于 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
中指定。