Google Map Android API V2 – Switching between Normal View, Satellite View and Terrain View

January 11, 2013

In this article, we will develop an Android Google Map V2 application which facilitates users to switch between different views ( Normal View, Satellite View and Terrain View ) by tapping corresponding radio buttons.

This application is an upgraded version of the application discussed in the article titled “Android Google Map – Switching between Map view and Satellite view” where Google Map Android API V1 is used.

For developing this application, we are using Eclipse 4.2.1 with ADT plugin ( 21.0.0 ) and Android SDK ( 21.0.0 ) and testing in a real device with Android 2.3.6  ( GingerBread ).

1. Download and configure Google Play Services Library in Eclipse

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

2. Create a new Android Application Project namely “LocationGoogleMapViewsV2″

Create new Android application project

Figure 1 : Create new Android application project

3. Configure Android Application Project

Configure new Android application project

Figure 2 : Configure new Android application project

4. Design Application Launcher Icon

Design application launcher icon

Figure 3 : Design application launcher icon

5. Create a blank activity

Create a blank activity

Figure 4 : Create a blank activity

6. Enter Main Activity Details

Enter Main Activity Details

Figure 5 : Enter Main Activity Details

7. Add Google Play Services Library to this project

Add Google Play Service Library to this project

Figure 6 : Add Google Play Service 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 window, Click “Android Tools -> Add Support Library “

10. Update the file AndroidManfiest.xml

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

        android:targetSdkVersion="16" />


    <uses-permission android:name="in.wptrafficanalyzer.locationgooglemapviewsv2.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" />



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

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

        android:layout_height="wrap_content" >

            android:checked="true" />

            android:text="@string/str_rb_satellite" />

            android:text="@string/str_rb_terrain" />


    <fragment xmlns:android=""


12. Update the file res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
    <string name="app_name">LocationGoogleMapViewsV2</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="str_rb_normal">Normal</string>
    <string name="str_rb_satellite">Satellite</string>
    <string name="str_rb_terrain">Terrain</string>

13. Update the file src/in/wptrafficanalyzer/locationgooglemapviewsv2/

package in.wptrafficanalyzer.locationgooglemapviewsv2;

import android.os.Bundle;
import android.view.Menu;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;


public class MainActivity extends FragmentActivity {

    GoogleMap googleMap;

    protected void onCreate(Bundle savedInstanceState) {

        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(;
        googleMap = mapFragment.getMap();


        RadioGroup rgViews = (RadioGroup) findViewById(;

        rgViews.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(checkedId =={
                }else if(checkedId =={
                }else if(checkedId =={


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

14. Screenshots of the application in execution

Google Map Android API V2 in Normal View

Figure 7 : Google Map Android API V2 – Normal View

Google Map Android API V2 - Satellite View

Figure 8 : Google Map Android API V2 – Satellite View

Google Map Android API V2 - Satellite View

Figure 9 : Google Map Android API V2 – Satellite View

15. Download 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: , , , , ,

12 Responses to Google Map Android API V2 – Switching between Normal View, Satellite View and Terrain View

  1. bouaoud on April 15, 2013 at 6:01 pm

    Thanks A LOT :)

  2. Wedar on April 22, 2013 at 3:47 pm

    Hai thank for the tutorial. but i get a problem :
    when i add googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    the app crash but when i delete it it works but the map won’t change to satelite or terrain view. sorry for bad english. thanks. hope i get the answer

    • george on April 22, 2013 at 5:18 pm

      Are you getting any error message in Logcat?

      • Wedar on April 23, 2013 at 8:12 am

        yes. it’s say null pointer exception

  3. andry yudha on May 9, 2013 at 11:49 am

    thanks george,, i love your tutorials :D

  4. ChulbulPandey on June 14, 2013 at 12:34 pm

    Like always, again such a nice tutorial, easy to learn and use, but this time i need your help, In same tutorial i wanna show 3 custom Locations, using Latitude and Longitude, Cities like: New Delhi, Mumbai and Bangalore, i hope you will add this functionality ASAP.

    Thanks in Advance

  5. Sanjay on June 26, 2013 at 5:40 pm

    Very nice Example and very help fully…………..

  6. agilene on July 2, 2013 at 2:19 pm

    Thank you so much for sharing to us :D

  7. Ashwini Saraf on September 4, 2013 at 3:08 pm

    09-04 14:47:18.053: E/AndroidRuntime(11779): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{in.wptrafficanalyzer.locationgooglemapviewsv2/in.wptrafficanalyzer.locationgooglemapviewsv2.MainActivity}: java.lang.ClassNotFoundException: in.wptrafficanalyzer.locationgooglemapviewsv2.MainActivity in loader dalvik.system.PathClassLoader[/data/app/in.wptrafficanalyzer.locationgooglemapviewsv2-1.apk]
    plz give reply …its urgen. :(

  8. Jalpa Patel on December 11, 2013 at 4:07 pm

    your code is working awesome..but the only prob is it is not showing compass in my map…can you plz help me in that ….

  9. Min Naing Oo on October 5, 2014 at 10:10 pm

    Thank you very much.

  10. Meow on February 16, 2016 at 8:37 pm

    George, you are the best Android teacher in the world!

Leave a Reply to Min Naing Oo Cancel reply

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

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner