Remove a single marker from Google Maps Android API V2 on clicking InfoWindow

April 26, 2013

In this article, we will develop an Android application which demonstrates how to remove markers individually from Google Maps Android API V2 on clicking InfoWindow.

On clicking ( taping ) a location in the Google Map, a marker is added to the clicked location. Then, on clicking the marker, an infowindow will be displayed and on clicking the infowindow, the marker will be removed from the Google Map.

This application is developed in Eclipse (4.2.1) with ADT plugin (21.1.0) and Android SDK (21.1.0) and tested in a real Android device (Android 2.3.6  -  GingerBread).

1. Create a new Android application project namely “LocationRemoveSingleMarker”

Create new Android application project

Figure 1 : Create new Android application project

2. Configure the project

Configure the application  project

Figure 2 : Configure the application project

3. Design application launcher icon

Design application launcher icon

Figure 3 : Design application launcher icon

4. Create a blank activity

Create a blank activity

Figure 4 : Create a blank activity

5. Enter MainActivity details

Enter MainActivity details

Figure 5 : Enter MainActivity details

6. Download and configure Google Play Services Library in Eclipse

Google Map for Android is now integrated with Google Play Services. So we need to set up Google Play Service Library for developing Google Map application in Android.

Please follow the given below link to setup Google Play Service library in Eclipse.

7. Add Google Play Services Library to this project

Link Google Play Services Library to this project

Figure 6 : Link Google Play Services Library to this project

8. Get the API key for Google Maps Android API V2

We need to get an API key from Google to use Google Maps in Android application.

Please follow the given below link to get the API key for Google Maps Android API v2.

9. Add Android Support library to this project

By default, Android support library (android-support-v4.jar ) is added to this project by Eclipse IDE to the directory libs. If it is not added, we can do it manually by doing the following steps :

  • Open Project Explorer by Clicking “Window -> Show View -> Project Explorer”
  • Right click this project
  • Then from popup menu, Click “Android Tools -> Add Support Library “

10. Update the layout file res/layout/activity_main.xml

<RelativeLayout xmlns:android=""
    tools:context=".MainActivity" >

        android:layout_height="match_parent" />


11. Update the class “MainActivity” in the file src/in/wptrafficanalyzer/locationremovesinglemarker/

package in.wptrafficanalyzer.locationremovesinglemarker;

import android.os.Bundle;
import android.view.Menu;


public class MainActivity extends FragmentActivity {

    GoogleMap googleMap;

    protected void onCreate(Bundle savedInstanceState) {

        // Getting Google Play availability status
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

        // Showing status
        if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available

            int requestCode = 10;
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);

        }else { // Google Play Services are available

            // Getting reference to the SupportMapFragment of activity_main.xml
            SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(;

            // Getting GoogleMap object from the fragment
            googleMap = fm.getMap();

            // Enabling MyLocation Layer of Google Map

            // Setting click event handler for map
            googleMap.setOnMapClickListener(new OnMapClickListener() {

                public void onMapClick(LatLng point) {
                    // Draw the marker at the taped position

            // Setting click event handler for InfoWIndow
            googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

                public void onInfoWindowClick(Marker marker) {
                    // Remove the marker

    private void drawMarker(LatLng point){
        // Creating an instance of MarkerOptions
        MarkerOptions markerOptions = new MarkerOptions();

        // Setting latitude and longitude for the marker

        // Setting snippet for the InfoWindow
        markerOptions.snippet("Tap here to remove this marker");

        // Setting title for the InfoWindow
        markerOptions.title("Marker Demo");

        // Adding marker on the Google Map

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(, menu);
        return true;

12. Update the file AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    android:versionName="1.0" >

        android:targetSdkVersion="17" />


    <uses-permission android:name="in.wptrafficanalyzer.locationremovesinglemarker.permission.MAPS_RECEIVE"/>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name=""/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


        android:theme="@style/AppTheme" >
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            android:value="YOUR_ANDROID_API_KEY" />

Note : Replace “YOUR_ANDROID_API_KEY” at the line 44 with Google Maps Android API V2 api key obtained in Step 8.

13. Executing the application

We can execute this application from the Eclipse IDE menu Run -> Run As -> Android Application

Sceenshot of the application in execution

Figure 7 : Sceenshot of the application in execution

14. Download the source code

How to hire me?

I am George Mathew, working as software architect and Android app developer at

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to

My other blogs

Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :

Tags: , , , , , ,

6 Responses to Remove a single marker from Google Maps Android API V2 on clicking InfoWindow

  1. chris on April 29, 2013 at 4:24 pm

    can you help me in a projet googlemap with a lot of marker data already exist but i don’t know how to put it on googlemap android
    i try a lot of thing but dont work

    please email me

    • george on April 29, 2013 at 5:33 pm

      Hello Chris,
      Please visit the article titled “Adding marker on touched location of Google Maps using Android API V2 with SupportMapFragment” which explains how to add a marker in Google Maps Android API V2.

      • chris on April 29, 2013 at 6:02 pm

        thank for your reply,
        i try this ans it work when i touch the screen, good
        ( it s the article)

        but for me it s more difficulte
        my data base is on web server ( mysql)
        i do a php file for give to android xml data, it s work
        but how to put this data in googlemap???
        i don t know
        thank very much for your help
        i see googlemap is for you nice.


  2. babu s on September 6, 2013 at 8:57 pm


    I want to remove other marker i created except the current location marker.what should i do?

    • Rohit Chandekar on November 6, 2013 at 2:08 pm

      Just do…………

      if (marker != null) {

      • sasi on September 30, 2014 at 4:35 pm


        I want to add multiple marker without using mapclick listener.please reply me.

Leave a Reply

Your email address will not be published. Required fields are marked *

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner