Home > Net >  Flutter Marker Icon Size
Flutter Marker Icon Size

Time:02-22

I tried to change marker icon size but i did not alread find true solutions. I used Uint8list with Google Map. I shared flutter code below this text. Can you help me :)

String imgurl = "http://cdn.arasikackm.com/harita/ankara-cankaya-gop-harita.jpg";
Uint8List bytes = (await NetworkAssetBundle(Uri.parse(imgurl),)
  .load(imgurl))
  .buffer
  .asUint8List();

  markers.add(
    Marker( //add start location marker
       zIndex: 1,
       draggable: false,
       anchor: const Offset(0.5, 0.5),
      markerId: MarkerId(startLocation.toString()),
      position: startLocation2, //position of marker
      infoWindow: const InfoWindow( //popup info 
        title: 'Starting Point ',
        snippet: 'Start Marker',
      ),
     
      icon: BitmapDescriptor.fromBytes(bytes),
      
     
    )
    
  );

`

CodePudding user response:

Go through the following discussion, It Is used for the google map marker icon.

https://stackoverflow.com/questions/53633404/how-to-change-the-icon-size-of-google-maps-marker-in-flutter#:~:text=Using an asset&text=final Uint8List markerIcon = await getBytesFromAsset,100 and 200 width respectively.

CodePudding user response:

you can use this method add hight and width to marker

Future<Uint8List> getBytesFromCanvas(int width, int height) async {
  final ui.PictureRecorder pictureRecorder = ui.PictureRecorder();
  final Canvas canvas = Canvas(pictureRecorder);
  final Paint paint = Paint()..color = Colors.blue;
  final Radius radius = Radius.circular(20.0);
  canvas.drawRRect(
      RRect.fromRectAndCorners(
        Rect.fromLTWH(0.0, 0.0, width.toDouble(), height.toDouble()),
        topLeft: radius,
        topRight: radius,
        bottomLeft: radius,
        bottomRight: radius,
      ),
      paint);
  TextPainter painter = TextPainter(textDirection: TextDirection.ltr);
  painter.text = TextSpan(
    text: 'Hello world',
    style: TextStyle(fontSize: 25.0, color: Colors.white),
  );
  painter.layout();
  painter.paint(canvas, Offset((width * 0.5) - painter.width * 0.5, (height * 0.5) - painter.height * 0.5));
  final img = await pictureRecorder.endRecording().toImage(width, height);
  final data = await img.toByteData(format: ui.ImageByteFormat.png);
  return data.buffer.asUint8List();
}
  • Related