Is flutter GoogleMap plugin exposes any ways to display custom markers? Can't find any way to do it based on documentation.

3 Answers

4
Franzé Jr. On

I'm using:

controller.addMarker(MarkerOptions(
  icon: BitmapDescriptor.fromAsset("images/restaurant.png"),
  position: LatLng(40.017870, -105.278350),
));

It works fine on Android, but it doesn't work on iOS.

0
Faxriddin Abdullayev On

Changing marker icon

MarkerOptions(
position: LatLng(41.4219999, 63.0862462),
infoWindowText: InfoWindowText("Yur Title", "Your Content"),
icon: BitmapDescriptor.fromAsset('images/your_image.png',),
),
1
kapil singh On

as per new plugin BitmapDescriptor.fromAsset("images/restaurant.png") is not working properly so refer this link and find my solution.

Future<BitmapDescriptor> _getAssetIcon(BuildContext context) async {
final Completer<BitmapDescriptor> bitmapIcon =
    Completer<BitmapDescriptor>();
final ImageConfiguration config = createLocalImageConfiguration(context);

const AssetImage('assets/red_square.png')
    .resolve(config)
    .addListener((ImageInfo image, bool sync) async {
  final ByteData bytes =
      await image.image.toByteData(format: ImageByteFormat.png);
  final BitmapDescriptor bitmap =
      BitmapDescriptor.fromBytes(bytes.buffer.asUint8List());
  bitmapIcon.complete(bitmap);
});

return await bitmapIcon.future;}

and use this like this

void _add(LatLng position,String address) async{
final MarkerId markerId = MarkerId('1');
BitmapDescriptor markericon = await _getAssetIcon(context);

// creating a new MARKER
final Marker marker = Marker(
  markerId: markerId,
  position: position,
  infoWindow: InfoWindow(title: address, snippet: 'go here'),
  icon: markericon
);

setState(() {
  _markers[markerId] = marker;
});}

hope it work for you.