Open In App
Related Articles

How to Add Custom Marker to Google Maps in Android?

Improve Article
Save Article
Like Article

Google Maps is used in many apps for displaying a location and indicating a specific location on a map. We have seen the use of maps in many apps that provides services such as Ola, Uber, and many more. In these apps, you will get to see How we can add Custom Marker to Google Maps in Android. 

What we are going to build in this article? 

We will be building a simple application in which we will display a map and on that map, we will be displaying a custom marker on our app. Below is the screenshot in which we will get to see what we are going to do in this project. we are going to implement this project in both Java and Kotlin languages. 


Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language. Make sure to select Maps Activity while creating a new Project.

Step 2: Generating an API key for using Google Maps

To generate the API key for Maps you may refer to How to Generate API Key for Using Google Maps in Android. After generating your API key for Google Maps. We have to add this key to our Project. For adding this key in our app navigate to the values folder > google_maps_api.xml file and at line 23 you have to add your API key in the place of YOUR_API_KEY. After adding this now we are ready for adding the custom marker to our app. After adding the API key, you can run your app and you will get to see a default marker on the Sydney location with the default marker. 

Step 3: Adding a custom marker in Google Maps

For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map. 

Step 4: Working with the file

Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.content.Context;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
public class MapsActivity
    extends FragmentActivity implements OnMapReadyCallback {
    private GoogleMap mMap;
    protected void onCreate(Bundle savedInstanceState)
        // Obtain the SupportMapFragment and get notified
        // when the map is ready to be used.
        SupportMapFragment mapFragment
            = (SupportMapFragment)
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to
     * be used. This is where we can add markers or lines,
     * add listeners or move the camera. In this case, we
     * just add a marker near Sydney, Australia. If Google
     * Play services is not installed on the device, the
     * user will be prompted to install it inside the
     * SupportMapFragment. This method will only be
     * triggered once the user has installed Google Play
     * services and returned to the app.
    @Override public void onMapReady(GoogleMap googleMap)
        mMap = googleMap;
        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions()
                           .title("Marker in Sydney")
                           // below line is use to add
                           // custom marker on our map.
    private BitmapDescriptor
    BitmapFromVector(Context context, int vectorResId)
        // below line is use to generate a drawable.
        Drawable vectorDrawable = ContextCompat.getDrawable(
            context, vectorResId);
        // below line is use to set bounds to our vector
        // drawable.
            0, 0, vectorDrawable.getIntrinsicWidth(),
        // below line is use to create a bitmap for our
        // drawable which we have added.
        Bitmap bitmap = Bitmap.createBitmap(
        // below line is use to add bitmap in our canvas.
        Canvas canvas = new Canvas(bitmap);
        // below line is use to draw our
        // vector drawable in canvas.
        // after generating our bitmap we are returning our
        // bitmap.
        return BitmapDescriptorFactory.fromBitmap(bitmap);


package com.example.map_custonm_marker
import android.content.Context
import android.os.Bundle
import androidx.core.content.ContextCompat
// Importing maps libraries
import com.example.map_custonm_marker.databinding.ActivityMapsBinding
// class
class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
    private lateinit var mMap: GoogleMap
    private lateinit var binding: ActivityMapsBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        binding = ActivityMapsBinding.inflate(layoutInflater)
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        val mapFragment = supportFragmentManager
            .findFragmentById( as SupportMapFragment
    override fun onMapReady(googleMap: GoogleMap) {
        mMap = googleMap
        // Add a marker in Sydney and move the camera
        val sydney = LatLng(-34.0, 151.0)
        val marker=MarkerOptions().position(sydney).title("Marker in Sydney")
        //set custom icon
        marker.icon(BitmapFromVector(getApplicationContext(), R.drawable.baseline_flag_24))
        //add marker
   private fun BitmapFromVector(context:Context,vectorResId:Int): BitmapDescriptor? {
       //drawable generator
       var vectorDrawable: Drawable
       vectorDrawable= ContextCompat.getDrawable(context,vectorResId)!!
       //bitmap genarator
       var bitmap:Bitmap
       bitmap= Bitmap.createBitmap(vectorDrawable.intrinsicWidth,vectorDrawable.intrinsicHeight,Bitmap.Config.ARGB_8888)
       //canvas genaret
       var canvas:Canvas
       //pass bitmap in canvas constructor
       canvas= Canvas(bitmap)
       //pass canvas in drawable
        //return BitmapDescriptorFactory
       return BitmapDescriptorFactory.fromBitmap(bitmap)

Now run your app and see the output of the app. 


Note: In the Google Developer Console (, ensure that the “Google Maps Android API v2” is enabled. And also ensure that your API Key exists.

Add Custom Marker to Google Maps in Android Output

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 18 Apr, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials