Android Google Maps

Aug 18, 2017
Get API key, add Google Play services, edit AndroidManifest.xml and use SupportMapFragment.

NOTE: Refer to Android Google Maps (Google Play Version 15) for latest guide.

Get API Key

Visit Get API Key to create an API Key. You can select an existing Google project or create a new one. Copy the API Key.

Google Maps Api Key

Add Google Play services

Make sure you already install Google Play services SDK (Android Studio > Tools > SDK Manager > SDK Tools > Support Repository > Google Repository).

Edit your application module's build.gradle to add google play dependencies.

apply plugin: ''

android {

dependencies {
    // Releases:
    // Entire google play services package
    // compile ''
    // Google Maps only, smaller library size and avoid 64K DEX limit.
    compile ''

Google Play services 11.2

If you are using Google Play services version 11.2, edit your project's build.gradle to add into repositories.

Note: If you don't add, it will show error Failed to resolve:

Note: Goole Play services release note: August 2017 - version 11.2.0 recommend adding using google(). This require Android plugin for Gradle version higher than 2.3.3, else it will show error Gradle DSL method not found: 'google()'.

Note: Goole Play services release note: August 2017 - version 11.2.0 mentioned you need compileSdkVersion of at least 26 (Android O) to use Google Play services 11.2. I manage to use compileSdkVersion 25 to compile and build

buildscript {

    dependencies {
        classpath ''

allprojects {
    repositories {
        // ADD THIS: require gradle version higher than 2.3.3
        // google()
        // ADD THIS: works the same as google()
        maven {
            url ''

Edit your application module’s build.gradle to add google play dependencies.

apply plugin: ''

android {

dependencies {
    compile ''


Edit AndroidManifest.xml and add the meta-data for and

If you need to access user's current location, include the location permissions as well.

Note: android.permission.INTERNET and android.permission.ACCESS_NETWORK_STATE is automatically merged into app's manifest at build time, thus don't need to explicitly include them.

Note: Support for OpenGL ES version 2 is automatically merged into app's manifest at build time as well.

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

    <!-- ADD THIS: If your application accesses the user's current location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <!-- ADD THIS: for Google Play services SDK before 8.3 -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application ...>
                <action android:name="android.intent.action.MAIN" />

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

        <!-- ADD THIS: Specify your API key -->
        <!-- ADD THIS: Specify the Google Play services version number -->
            android:value="@integer/google_play_services_version" />


Edit layout file

Edit you activity's layout file to add SupportMapFragment.

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

        android:layout_height="match_parent" />


Add code

Add code to retrieve SupportMapFragment and register map callback using getMapAsync.

public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        ...        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(;        mapFragment.getMapAsync(new OnMapReadyCallback() {            @Override            public void onMapReady(GoogleMap googleMap) {                LatLng latLng = new LatLng(1.289545, 103.849972);                googleMap.addMarker(new MarkerOptions().position(latLng)                        .title("Singapore"));                googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));            }        });    }

Your first Android Google Maps with a single marker is ready :)


❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.