How to place a location on Google Map

Here are few steps on how to add Google Map to your Kotlin/Android project, in this post, there are two things:

  • Show marker on Google Map
  • Get current location (Latitude & Longitude)

Show marker on Google Map

Step 1: Add dependencies in build.gradle:

compile ''

Step 2: Set up Google Maps API Key in the AndroidManifest.xml. One example of the whole manifest file could be:


Notice: Be careful about the <meta-data>’s location in the file. Error happened if it is outside &lt;application&gt;. You can obtain an API key from

Step 3: Setup UI in the resource file, the following example is using Fragment:

Notice: Use

Get current location (Latitude & Longitude)

Step 1: Add dependencies in build.gradle:

compile ''
compile ''

Step 2: Add necessary permissions and set up Google Maps API Key in the AndroidManifest.xml with the example above:

Step 3:


First, the class is implemented an interface named OnMapReadyCallback, which will override a method named onMapReady

Second, then define a locationRequest used to handle the google map request, a variable named UPDATE_INTERVAL and FASTEST_INTERVAL to set up map update frequency.

Third, create a method named startLocationUpdates to initalize the mGoogleMap and setup locationRequest, including a Priority, Interval and FastInterval. Then create a location setting request builder and LocationCallback which actually return the updated information.

Fourth, since the android version 23 and above, the system will ask users for the permissions. We added a function to determine whether do we need extra permission or not.

You can have a look at the whole project at:


About: arkilis

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.