Android SupportMapFragment Example - Truiton
Skip to content

Android SupportMapFragment Example

Android SupportMapFragment Example

Now days almost all Android apps have some sort of interaction with Google Maps Android API v2. This tutorial Android SupportMapFragment Example, is a part of my series of three on Google Maps Android API v2. In my previous tutorial on Android MapFragment, I mentioned a drawback of MapFragment, that it cannot be used on devices running Android API below version 12. The answer to this problem is Android SupportMapFragment. At Truiton I was developing an app in which we used Android SupportMapFragment class, so thought of sharing it with community. I was developing that app for Android Gingerbread  v2.3.3 i.e. API 10, but since MapFragment class cant be used, I used Android SupportMapFragment class.

The usage of Android SupportMapFragment is same as its sibling, the only difference is that, instead of using Activity class we would have to use FragmentActivity class. The reason for doing this is, we need to use a method getSupportFragmentManager(), and this method can be called in FragmentActivity class only.

In this Android SupportMapFragment Example I will not be explaining on how to generate a Google Maps Android API v2 key or how to create a project with Google Play Services SDK library. If you need to understand how to do these tasks please read my tutorial on Android MapFragment.

Android SupportMapFragment Example

I assume, by now you have a project set up with Google Play Services SDK and generated a Google Maps Android API v2 key, refer this article if you have not. Lets proceed with AndroidManifest.xml:

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

        android:targetSdkVersion="17" />

        android:protectionLevel="signature" />

        android:required="true" />

    <uses-permission android:name="com.truiton.supportmapfragment.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="" />
     The following two permissions are not required to use
     Google Maps Android API v2, but are recommended.
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

        android:theme="@style/AppTheme" >
            android:value="@integer/google_play_services_version" />

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

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

            android:value="Input-API-Key-Here" />


lets discuss the marked lines in above Android SupportMapFragment Example manifest. In lines 7-9 you can see minimum sdk version 8 is specified as this is an Android SupportMapFragment example. Next in lines 11-13 we are defining a permission with our app package to access Google Maps Android API v2, and using the same in line 19. To display Google Maps on your device please specify your API key at line 48.

Next lets have a look at the layout file:

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

        class="" />


Here in the activity_support_map_fragment.xml I defined a fragment with class, this fragment is used to display Android SupportMapFragment.

The main class which displays map is :

package com.truiton.supportmapfragment;


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

public class SupportMapFragmentActivity extends FragmentActivity {

 protected void onCreate(Bundle savedInstanceState) {

 FragmentManager fmanager = getSupportFragmentManager();
        Fragment fragment = fmanager.findFragmentById(;
        SupportMapFragment supportmapfragment = (SupportMapFragment)fragment;
        GoogleMap supportMap = supportmapfragment.getMap();


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


In this, I extended FragmentActivity as we are using Android SupportMapFragment. And as I stated before to use Android SupportMapFragment class we need to call getSupportFragmentManager() method. Therefore we need to extend FragmentActivity class.

By now you might have guessed that its pretty much same as Android MapFragment. Therefore I’d like to conclude the tutorial Android SupportMapFragment Example, and conclude my series on Google Maps Android API v2. In this tutorial I gave an overview of Android SupportMapFragment class and explained how to display Google Maps on Android device with an API version lower than 12. Hope this helped you, if it did please like and share this on Google+ and Facebook also like our Facebook page for updates.

7 thoughts on “Android SupportMapFragment Example”

  1. Hi,
    I also used the same SupportFragmentManager but im getting a error in the line setContentView(R.layout.main); it says
    I have already added google support Library.
    Pls help me

    1. Hey,

      Are you getting this error on line getMenuInflater().inflate(, menu); as this a menu xml. You need to add an xml file by the name of support_map in res/menu folder, or you can remove this method all together.

  2. Great tutorial but… android.view.InflateException: Binary XML file line #13: Error inflating class fragment

    android.view.InflateException: Binary XML file line #13: Error inflating class fragment
    at com.quexjh.cfeapp.MapActivity.onCreate(

    the line 26 is setContentView(R.layout.activity_support_map_fragment);

    help please!!

      1. Hello Aron, Senou

        Thanks allot for pointing it out. Seems like I missed out an element which was required in the application element of manifest. Now corrected.

        Please check the manifest code in tutorial above.


Leave a Reply

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