How to change the icon size of Google Maps marker in Flutter?

前端 未结 14 735
不知归路
不知归路 2020-12-07 12:32

I am using google_maps_flutter in my flutter app to use google map I have custom marker icon and I load this with BitmapDescriptor.fromAsset(\"images/car.

14条回答
  •  一整个雨季
    2020-12-07 13:21

    So you can try the Ugly way . MediaQuery will return the ratio and check for conditions manually something Like so

     double mq = MediaQuery.of(context).devicePixelRatio;
     String icon = "images/car.png";
     if (mq>1.5 && mq<2.5) {icon = "images/car2.png";}
     else if(mq >= 2.5){icon = "images/car3.png";}
      mapController.addMarker(
        MarkerOptions(
           icon: BitmapDescriptor.fromAsset(icon),
           position: LatLng(37.4219999, -122.0862462),
         ),
       );
    

    you need to add your different assets images in your images folder like

    -images/car.png
    -images/car2.png
    -images/car3.png
    

提交回复
热议问题