Flutter Network Image作为Google Map Marker

时间:2019-07-24 13:36:28

标签: flutter dart

我想在屏幕上显示的Google地图上添加网络图像作为标记。该API支持功能Bitmapdescriptor.fromBytes()。但是,我不知道如何将其与网络映像一起使用。

BitmapDescriptor.fromBytes(byteData);

1 个答案:

答案 0 :(得分:2)

首先导入此内容:-

              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",
                  ),
                ));