Contents
Coding With Dhrumil

HomeArticles

Custom Markers in Flutter Google Maps: A Practical Guide

By Dhrumil PatelPublished 4 min read

Google Maps is a staple in many Flutter apps, and custom markers are often the first thing developers want to change. The default red pin is fine for a prototype, but production apps need branded icons, status indicators, or even interactive widgets. This guide walks through the practical options, from the basic BitmapDescriptor to advanced widget-based markers, and shares performance numbers you can expect.

We'll cover the common pitfalls: marker lag on Android, memory leaks from undisposed images, and the trade-offs between using asset images, network images, and custom widgets. By the end, you'll know which approach fits your use case and how to keep your map smooth even with hundreds of markers.

Understanding BitmapDescriptor: The Foundation

Every marker in google_maps_flutter uses a BitmapDescriptor to define its appearance. The plugin provides factory constructors: defaultMarker, fromAsset, fromAssetImage, fromBytes, and fromNetwork. Each has different performance characteristics. fromAsset is the fastest because the image is bundled and decoded once; fromNetwork introduces latency and requires error handling. For static icons, always prefer assets.

A common mistake is calling BitmapDescriptor.fromAsset repeatedly inside build methods. This creates a new descriptor each time, causing unnecessary image decoding and marker flicker. Cache your descriptors in a state variable or a singleton, and reuse them across markers. If you need multiple sizes, precompute them at startup rather than on demand.

  • Use fromAsset for icons that ship with the app.
  • Cache descriptors; avoid creating them in build().
  • For network images, handle loading and errors gracefully.
  • Prefer PNGs with transparent backgrounds for pin shapes.

Creating Custom Marker Icons with Assets

The simplest way to get a custom marker is to design a PNG and load it with BitmapDescriptor.fromAssetImage. This method lets you specify the image path and a configuration object that controls scaling. On Android, the image is decoded at the device's pixel density, so a 48x48 logical pixel marker might need a 144x144 asset for xxhdpi screens. Test on multiple densities to avoid blurriness.

If your markers need dynamic text (like a price or a count), you can generate images at runtime using the flutter Canvas API and convert them to bytes with BitmapDescriptor.fromBytes. This is more expensive than static assets but gives you full control. Limit runtime generation to a few dozen markers; beyond that, consider pre-rendering common variants.

  • Design markers at 3x resolution for crisp display.
  • Use fromAssetImage with ImageConfiguration for density-aware loading.
  • For dynamic content, render to a ui.Image and convert to bytes.
  • Keep marker file sizes under 50 KB to reduce memory.

Advanced: Widget-Based Markers

Sometimes a static image isn't enough—you want a marker that shows a live avatar, a progress indicator, or a tappable button. The google_maps_flutter plugin doesn't support widgets directly as markers, but you can achieve a similar effect by rendering a widget to an image using RepaintBoundary and toImage. This approach lets you use any Flutter widget, including text, icons, and even simple animations.

The trade-off is performance. Rendering a widget to an image is costly, often taking 10-30ms per marker on mid-range devices. For a map with 20 markers, that's acceptable if done once; for 200 markers, you'll see jank. Use this technique sparingly, and cache the resulting BitmapDescriptor. Also, remember that the rendered image is static—if the widget updates, you must re-render and update the marker.

  • Wrap your widget in RepaintBoundary and call toImage.
  • Convert the ui.Image to bytes and use BitmapDescriptor.fromBytes.
  • Cache the descriptor; re-render only when the widget changes.
  • Limit to a few dozen markers for smooth performance.
810 markers1250 markers18100 markers28200 markers45500 markers
Frame render time vs marker count (mid-range Android) (ms per frame)

Handling Marker Taps and Info Windows

Custom markers often need to respond to taps. The GoogleMap widget's onTap callback provides the LatLng, but to know which marker was tapped, you must compare coordinates or use a unique identifier. A common pattern is to store a map of MarkerId to your data model and check onTap against each marker's position with a small tolerance (around 0.0001 degrees).

Info windows are the popups that appear when a marker is tapped. By default, they show a title and snippet, but you can customize them with your own widget using the infoWindow property. However, custom info windows have limitations: they don't support scrolling or complex interactions. For rich content, consider showing a bottom sheet or dialog instead of an info window.

  • Use MarkerId as a key to map to your data.
  • Compare tapped LatLng with marker positions using a tolerance.
  • Custom info windows are static; use a bottom sheet for interactivity.
  • Set consumeTapEvents to true if you want to handle taps yourself.

Performance Considerations and Real-World Numbers

Marker performance varies by platform and device. On a mid-range Android phone (e.g., Snapdragon 660), rendering 100 static asset markers typically takes 16-20ms per frame, which is close to the 16ms budget for 60fps. Beyond 200 markers, you'll likely see dropped frames. On iOS, performance is generally better, but memory usage grows with marker count.

To keep things smooth, cluster your markers when zoomed out. The google_maps_flutter plugin doesn't include clustering, but you can implement a simple grid-based clusterer or use a package. Also, avoid updating markers on every camera move; debounce updates to once every 200-300ms. Finally, dispose of any images you create to prevent memory leaks, especially on Android.

  • Keep marker count under 100 for smooth 60fps on mid-range devices.
  • Implement clustering for large datasets.
  • Debounce marker updates during camera moves.
  • Dispose ui.Image objects after converting to bytes.

Common Pitfalls and How to Avoid Them

One frequent issue is marker flicker when the map rebuilds. This happens when you recreate BitmapDescriptors or Marker objects unnecessarily. Ensure your marker list is stable and only changes when data changes. Another pitfall is using network images without caching; this causes markers to reload on every map interaction, wasting bandwidth and causing lag.

On Android, large marker images can cause out-of-memory errors, especially on low-end devices. Keep marker dimensions under 100x100 logical pixels and compress images. Also, be careful with marker rotation and anchoring; incorrect anchor values can make markers appear offset. Test on multiple screen sizes to ensure consistent placement.

  • Avoid recreating markers in build(); use a stateful widget or provider.
  • Cache network images locally.
  • Limit marker size to 100x100 logical pixels.
  • Set anchor correctly for custom pin shapes.
Comparison of marker image sources in Flutter Google Maps
SourceLoad Time (first)Memory per MarkerBest For
Asset (fromAsset)< 5ms~50 KBStatic branded icons
Network (fromNetwork)100-500ms~100 KB + cacheDynamic icons from API
Bytes (fromBytes)10-30ms (render)~80 KBWidgets rendered to image
Default marker0ms~20 KBPrototypes, fallback

Key points

  • Use asset-based BitmapDescriptors for most custom markers; cache them to avoid flicker.
  • Render widgets to images only for a small number of markers due to performance cost.
  • Keep marker count under 100 for smooth 60fps on mid-range devices; cluster for larger datasets.
  • Handle taps by mapping MarkerId to data and comparing coordinates with tolerance.

Flutter Screen Widget and Cost Estimator

Estimate the number of widgets in a screen and a rough development-hour figure from your component counts. Adjust the fields to see how each UI area affects the total effort.

Calculate

Dhrumil Patel

Editor and Flutter contributor

Writes practical Flutter tutorials focused on widgets, layout and animation. Enjoys breaking large UI problems into small, testable pieces and explaining them clearly to beginners.

Related articles

Cupertino vs Material Widgets: Which Style Fits Your App?

Compares look, platform behavior and maintenance effort of the two Flutter design systems.

Flutter Installation Checklist for Windows and macOS

A numbered setup checklist covering SDK, editor plugins and emulator verification.

StatelessWidget vs StatefulWidget: Which One Should You Pick?

A side-by-side comparison of lifecycle, rebuild cost and when each choice keeps code simpler.