Add Google Maps to your Android App

You can find the corresponding udacity course here.

Table of Contents

  1. Play services
  2. Maps
  3. Markers
  4. StreetView

Play services

To use them add to the build.gradle:

compile ''

Then add to the Manifest:


Create GoogleApiClient in onCreate()

Connect GoogleApiClient in onStart() to Location Service (or other relevant API)

Overwrite onConnectionFailed() and onConnectionSuspend() in Location Service

Write onConnected() and create a LocationRequest that queries the Location Service

Write onLocationChanged() and get the Location object which you can then use


Generate a SHA 1 Key from the terminal by typing:

cd ~/.android

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

Go to developers console. Create a project. Activate Maps API. Generate an API Key for Andorid App and enter your SHA 1 and packagename.

Maps fragment

Create an xml fragment with


Set attributes on the map fragment:


Google maps object

Allows you to change your map while the app is running.

Look here

Camera Position Options

Use moveCamera() instantaniously move to a target. Use animateCamera() to go to a target with a fly over effect.


MarkerOptions myPlace = new MarkerOptions()
	.position(new LatLng(47.489805, -122.120502))
	.title("My Place")

⚠ Making an initial invisble marker visible is faster than creating a new marker => Great way to implement place filtering! (Ex.: Hide or show Hotels with specific cost levels)

Show or Hide markers info window programatically with marker.showInfoWindow() or marker.hindeInfoWindow()

Create an InfoWindowAdapter to fully customize the appereance of an marker’s info window.

Implement .setOnMarkerClickListener() to kick off other actions when clicking on the marker.

Implement .onInfoWindowClick() to kick off other actions when showing an info window on a marker click.

Custom Markers

Add icon property to MarkerOptions with .icon(BitmapDescriptionFactory.fromResource(R.drawable.ic_launcher));


Creates a trace for all the LatLng you add to the Polyline with:


Get to the initial one back at the end to get a Polygone.


In onMapReady() add:

m_map.addCircle(new CircleOptions()
     .center(new LatLng(47.489805, -122.120502))
     .radius(5000) // = 5 km


By default these 3 options are enabled, manage them with the following, if you like:

User interaction: