How to make custom pins in Google Maps for Android

Alexander Shevelev
2 min readFeb 7, 2021

Google Maps is a popular and powerful tool. And you can embed it in an Android application. But, I reckon you know it. What you may not know is how to make pins with a custom design (you can draw whatever you want, and you’ll see it yourself in a few seconds).

I want to say right now what you’ll not discover in this article. I’m not going to describe how to embed a Google Map in your app. I consider, you know how to do it, or you can read this manual from Google, or, I hope, you’ll see my sample to this article.

Let’s return to custom pins. A standard map’s pin is boring and dull. See it for yourself. Would you like to get something like this one? A piece of cake!

A traditional pin and now so traditional one — see the difference.

First thing you need to know — a custom pin is a bitmap. It sounds relatively simple now — you should draw a bitmap and place it on a map instead of a pin.

In my demo project, I made an example, how to create such a bitmap. You can find it in PinDraw class. It makes no sense to explain how it works here. Only to say, I use a standard Canvas class to do the job.

In addition to a bitmap, you should calculate an anchor point to display a pin correctly. Let’s look at this illustration.

An anchor point

As you can see, an anchor point is a pin’s spearhead, pointed precisely to a place on a map, which the pin is linked in. This value is consists of two parts (“x” and “y”), each of them is relative (take matters from 0 to 1, both values are inclusive). For my kind of a pin, a “y” value is always 1, and an “x” value depends on text length.

Now everything is ready to put a pin on a map. The code is quite simple:

And, Bob’s your uncle — now you know how to make custom pins for Google Maps. All source code for the article you can find here.

--

--

Alexander Shevelev

An Android developer from Yandex LLC, Moscow, Russia. That’s all.