【问题标题】:Change size of a custom marker Google-Maps [duplicate]更改自定义标记 Google-Maps 的大小 [重复]
【发布时间】:2020-10-29 06:48:13
【问题描述】:

我创建了一个应用程序,当您在地图中点击时,它会在 Google 地图中显示一个自定义标记,但我找不到更改标记大小的方法...有人知道我该怎么做吗?

这是 m 代码的一部分:

  createMarker(context) {
    if (customIcon == null) {
      ImageConfiguration configuration = createLocalImageConfiguration(context);
      BitmapDescriptor.fromAssetImage(configuration, 'assets/Boot-Pfeil2.png')
          .then((icon) {
        setState(() {
          customIcon = icon;
        });
      });
    }
  }


Marker m = Marker(
    markerId: MarkerId('1'),
    icon: customIcon,
    position: cordinate);
 setState(() {
    markers.add(m);
 });

【问题讨论】:

标签: google-maps flutter dart google-maps-markers google-maps-flutter


【解决方案1】:

基于this问题:

import 'dart:ui' as ui;
Future<Uint8List> getBytesFromAsset(String path, int width) async {
  ByteData data = await rootBundle.load(path);
  ui.Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List(), targetWidth: width);
  ui.FrameInfo fi = await codec.getNextFrame();
  return (await fi.image.toByteData(format: ui.ImageByteFormat.png)).buffer.asUint8List();
}

然后:

final Uint8List markerIcon = await getBytesFromAsset('assets/Boot-Pfeil2.png', 100);
final Marker marker = Marker(icon: BitmapDescriptor.fromBytes(markerIcon));

【讨论】:

    猜你喜欢
    • 2020-05-10
    • 2013-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-14
    • 1970-01-01
    • 2017-03-02
    相关资源
    最近更新 更多