๐ท๏ธ Custom Marker Labels

The materials presented in this chapter deal with low-level APIs. If you're using a framework like React or Angular, make sure to check out the chapter on Working with Frameworks .
Out of the box, Google Maps lets you add alphanumeric marker labels via the label
property .
These labels were originally designed for rather simple use cases like navigation โ think routing from A
to B
via C
.
As the web evolved, people started replacing default markers with increasingly complex shapes โ think real estate listing pins, marker clusters, brand logos and such.
To address this, Google gave developers a helping hand by releasing libraries like the v3-utility-library
and esp. markerwithlabel
.
These libraries abstracted away some complexity but most people still resorted to either:
- static, server-generated image icons accessible via URLs
- or dynamic, SVG-based icons which offered the most customizability.
To this day, custom marker labels pose a challenge to Google Maps newbies and practitioners alike. In this chapter, we'll reduce the complexities of marker labels to the minimum and learn how to bend them to our will.
I'm developing a Google map for the โCareersโ page of a restaurant chain. I want:
- The restaurant logo to replace Google's default red pins.
- To display a โbubbleโ with the number of open positions in the top right corner of each pin.
Unless you're using markers to indicate approximate locations or mark larger areas, your markers will always pinpoint a precise location. After all, that's where the thumbtack/pin emojis ๐ ๐ come from โ their bottom end locates the point of interest.

Default pin
Now, if your custom pin image doesn't have a V-shaped edge, the target location will be unintentionally ambiguous!

Ambiguous pin
Having a V-shaped edge on either side of the pin clearly marks the target location and removes any ambiguity from the picture.
V-shaped bottom edges (โtapered stemsโ) are the de-facto standard on real estate websites. See for instance Garages-Near-Me.com .

V-shaped bottom edge
Generally speaking, your markers should:
- adhere to the general design recommendations for Google Maps
- be large enough to be easily distinguishable from other elements on the map
- be made accessible through the
title
property and by settingoptimized
tofalse
.
Given an image URL like of known dimensions (eg. 145 x 158px), we'll quickly notice that's its too big for the map: