Add Marker to Google Map in Android Application


In the previous tutorial, you learned about the Integration of Google Maps API in Android application. In this tutorial, you will learn how to place a pin on the current location in Google Maps Android Application. To add Marker to Google Map in Android application, you must have running Google Maps on Android.

In this tutorial, you will learn how to make use of Network Provider and GPS Provider, as alternates. If GPS doesn’t work or if GPS device is switched off, the application will get longitude and latitude from Network Provider.

Components to Show Current Location in Google Maps

When using the built-in device services to get the physical location of the device, you will need following components. Consider a class GPSTracking which will act as a service and get the longitude and latitude by using GPS and Network Provider.


Whenever you need values in longitude and latitude, you can make use of Location class in Android.

To import Location in your Android application


When you want to consume system location services, you can use LocationManager. LocationManager helps Android applications to get their Geographical location.

To import LocationManager


The class which needs the location of the device must extend the Service as the class will act as a service.

To Import Service


Your GPSTracking class must implement LocationListener. LocationListener gets the location from the LocationManager.

To include LocationListener

You must also implement the required functions of LocationListener.

Setting up Environment

You must provide permissions to access the network and GPS components along with the internet in AndroidManifest.xml

Also, add dependencies for Google Maps in the build.gradle(module: app) file’s dependencies.

Get Location in Android Application

There are two ways to get location by using LocationManager. 

  1. Get Location from the network.
  2. Get Location from the GPS.

Before you get the location, you must check whether the network or GPS is available on the device or not.

Get Location from Network

To get location from the network use the object of LocationManager and request location update


Location in Longitude and Latitude

Get Location from GPS

Get location from GPS by using LocationManager’s object.

Dropping a Marker to Google Map Android Application

When using a fragment, your Activity must implement the functionality of OnMapReadyCallback interface. Get the map asynchronously after getting the map fragment in

To get the map fragment use the instance of MapFragment class. As GetMap() is deprecated so you can use getMapAsync() from the map fragment. 

Get Map Fragment in Code

Get Asynchronous Map


Permit Android Application to Enable Location on Device

Instantiate the GPSTracking class and enable the location.

Move Camera to the Location of Pin

Move the camera to GoogleMap area, where you want the pin. You need newlatlngzoom() method of CameraUpdateFactory class which takes longitude and latitude.

Set Type of Map

There are four types of Google Map

Hybrid View:

Satellite View:

Terrain View:



Drop Marker to Google Map

To place a Marker to Google Map, use AddMarker() method of GoogleMap class, it takes MarkerOptions title and snippet along with longitude and latitude of the device.

onMapsReady() Overridden Method will look like


Pin on Google Map
Pin on Google Map

Download Demo Project of this Application

Complete Code for

Complete Code of

Download Demo Project of this Application

Hope that you like this tutorial, Stay tuned for more upcoming tutorials. Stay Blessed!

Leave a Reply

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