This tutorial is to teach you how to add Google maps to an application. The main idea behind this tutorial is to open Google maps in an application and show a marker on it with our current location that’s also visible on the map.

For this purpose we will be using the Google Maps V2 API that Google provides in its API console and will also be implementing fragments and the Google Play Services library in the project.

Here is the screen shot of the final application.



Google Play Services provides you with easy access to Google  services and is tightly integrated with the Android OS. Easy to use client libraries are provided for each service that allows you to implement the functionality you want, easier and faster.

To read more about Google Play Services, please click here.

Part A:

Including Google Play services.

For accessing the Google Maps API we will need to import the Google Play Services to our workspace.

  1. Downloading Google Play Services
    First we will check whether we have Google Play Services in our SDK.

    1. Open Eclipse.
    2. Go to windows > Android SDK Managers .
    3. Go to Extras.
    4. If you do not have the Google Play Services  already installed, please select and click on Install package.
    5. Read and Accept the licence and click Install.


  2. Importing Google Play Services.

    Now we will include the above library in our workspace.

    1. Go to File > import > android > existing android code into workspace.
    2. Browse to your SDK folder and go to extras > google > google play services >
    3. libproject > google_play_services_lib and click ok and then import the project.



  3. Linking Google Play Services to our project.

    To use Google Play Services in the project, we need to include the above imported library to our project.

    1. Right click on the project
    2. Go to properties > android > add
    3. Look for the google-play-services library and add it to the project.
    4. A green tick will confirm a successful include.



Part B:

Getting your API key

To have access to our maps, we will need an API key which we will paste into our application.

  1. For this we will need the SHA1 Fingerprint of our default keystore.
    Go to Android > Preferences > Android > Build.
    or follow:
    For windows ->

    For Mac / Linux ->

  2. Now open the Google API console or Click here.
  3. Go to APIs and find the Google Maps Android API v2 and click on OFF status.

     Screenshot (49)

  4. Go to Credentials and click on Create New Key > Android Key.


  5. Paste your SHA1 Fingerprint and then your package name separated by a semicolon.


  6. Your API Key has been generated for your specific package.

Part C:

Working on the application.

  1. In your XML file, Drag and drop the fragment under Layout and then select Mapfragment.image11

    Or paste the following code into a XML file:

    Listing 1:

    Create a file called activity_main.xml

  2. Go to the AndroidManifest.xml file and provide the following permissions. Change your package name to replace “”.


  3. Now we will provide our API key to our application. Copy/paste the tag found below in your permission tag after of all the activity tags.
    Snippet 3:


  4. Include the above file in your Java class.
    Snippet 4:



  • Working with markers:

    Markers are pointers to a specific location defined by the latitude and longitude of that point. To add a marker, we will use the MarkerOptions() class.

    Snippet 5:

    Here, a marker is added to the location (28.573208 , 77.206383) with the title “Delhi Haat” as its name.

    Below is the screen shot to the added marker :

  • Notice that our map does not open over the defined marker and is zoomed out. We will use the moveCamera() function to move the camera to a specific position.

    Snippet 6:

    The first two numbers are the latitude and longitude where you want your map to point and the third is the zoom level to which your map is zoomed in/out.

    The desired zoom level is in the range of 2.0 to 21.0. Values below this range are reset to 2.0, and values above it are reset to 21.0. Increase the value to zoom in. Not all areas have tiles at the largest zoom levels.

    Or you can add the code below to zoom in on your map with an animation.

    Snippet 7:


  • If we want to change the colour of our marker, we can. 10 colours are defined by the Android library to use.

    Snippet 8:

    There are several other predefined marker icons in the Android library.


  • To add a custom marker icon, add the code below in the markerOptions() and change the path to your image file.

    Snippet 9:


  • To make it draggable and add a sub message to it, add the tags below to the markerOptions().

    Snippet 10:

    You can read more about markers HERE.

  • Changing Map Type
    Google provides 4 types of maps. Normal, Hybrid, Satellite, and Terrain. You can change to any kind of map using the map.setMapType() method.
    Different map type options
    Snippet 11:

  • Miscellaneous Map options

    Snippet 12:


    • To view the current location on the map, add the code below.

      Snippet 13:

    • To get rid of the zoom controls and zoom functionality, add the code below.

      Snippet 14:

    • To disable the compass from your map, add the code below.

      Snippet 15:

    • To enable a current location button to redirect the user to the current location when clicked, add the code below.

      Snippet 16:

    • To enable tilt and/or rotation functions from your map, add the code below.

      Snippet 17:


Listing 2:

Create a java file MainActivity:


This was all about including Google Maps in your application. If you have any suggestions or have any errors while implementing this procedure, feel free to comment below.