Flutter 网络图像作为 Google 地图标记

2024-05-17

我想在屏幕上的谷歌地图上添加网络图像作为标记。 API确实支持一个功能Bitmapdescriptor.fromBytes()。但是,我不知道如何将它与网络图像一起使用。

BitmapDescriptor.fromBytes(byteData);

首先导入这个:-

              import 'package:http/http.dart' as http;

主要代码:-

              var iconurl ="your url";
              var dataBytes;
              var request = await http.get(iconurl);
              var bytes = await request.bodyBytes;

              setState(() {
                dataBytes = bytes;
              });

              LatLng _lastMapPositionPoints = LatLng(
                  double.parse("22.7339"),
                  double.parse("75.8499"));

                _markers.add(Marker(
                  icon: BitmapDescriptor.fromBytes(dataBytes.buffer.asUint8List()),
                  markerId: MarkerId(_lastMapPositionPoints.toString()),
                  position: _lastMapPositionPoints,
                  infoWindow: InfoWindow(
                    title: "Delivery Point",
                    snippet:
                    "My Position",
                  ),
                ));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Flutter 网络图像作为 Google 地图标记 的相关文章