Chapters

Hide chapters

Android Apprentice

Fourth Edition · Android 11 · Kotlin 1.4 · Android Studio 4.1

Section II: Building a List App

Section 2: 7 chapters
Show chapters Hide chapters

Section III: Creating Map-Based Apps

Section 3: 7 chapters
Show chapters Hide chapters

13. Creating a Map-Based App
Written by Namrata Bandekar

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Have you ever been on a road trip and wanted to make notes about the places you’ve visited; needed to warn your future self about some heartburn-inducing greasy food from a roadside diner; or you wanted to keep reminders about the best menu items at your favorite local restaurants?

If you answered “yes” to any of those questions, then you’re in luck! You’re about to build PlaceBook, an app that meets all of those needs by letting you bookmark and make notes using a map-based interface.

Getting started

While building PlaceBook, you’ll use familiar techniques from the previous sections and learn about several new Android APIs. Along the way, you’ll use:

  • Google Maps API to display a map, track the user’s location and add custom markers.
  • Google Places API to display place information and search for nearby places.
  • Room Persistence Library to store data.

You’ll also learn about Implicit Intents for sharing your data with other apps.

There’s a lot of ground to cover, but in the end, the final product will look like this:

About PlaceBook

PlaceBook starts by displaying a Google Map centered around your current location. The map will display common places, and allow you to bookmark them. You can display details for bookmarked places and edit the place data and a corresponding photo.

Making a plan

With a large number of features to implement, it’s best to think about them in bite-sized pieces. From there, you can slowly build-up to the finished product. The steps you’ll take to accomplish this are as follows:

Location service components

The Android SDK provides three main components related to location and mapping:

Map wizard walk-through

To save time, you’ll use the Maps Activity project template to generate an app with a single Activity that displays a map.

Google Maps API key

Before your app will work, you need to generate an API key using the free Google Developer Console, which requires a Google account.

Getting the keystore fingerprint

Although Android Studio conveniently placed your debug keystore fingerprint in the XML file, it’s helpful to know how to get the fingerprint yourself should you ever need to regenerate it. The following instructions work for debug builds; getting the SHA1 key for release builds is covered in Section VI, “Submitting Your App”.

Maps and the emulator

If you’re installing on a device, that’s all you need. However, if you’re using an emulator, then things can get a little more complicated.

Running the app

Launch the app from Android Studio.

Project dependencies

Before you can use maps in your app, you have to add the two required dependencies. To find the first one, open build.gradle from your application module folder. In the dependencies section, you’ll see the following line:

The manifest

First, from app/manifests, open AndroidManifest.xml. It’ll look like the following, with your API key displayed in place of @string/google_maps_key:

The activity and layout

Open MapsActivity.kt. This is the startup Activity created from the Maps template. Note that it inherits from AppCompatActivity and the OnMapReadyCallback interface.

Map display options

There are two ways to display a map in your app:

Asynchronous map setup

When you call getMapAsync(), the SupportMapFragment object handles all of the work of setting up the map and creating a GoogleMap object. The GoogleMap object is what you’ll use to control and query the map.

The difficulty of determining locations

Determining a user’s location is a rather involved process under the hood. There are multiple sources of location data to handle, and they all affect your device’s idea of where it is in the world.

Pexegout uninrw ofez paga
Xuzeniox ebabth iqeq xeru

Key Points

As you can see, there are many moving parts, and there is a lot of code required to provide a seamless experience for the user. Thankfully, the location APIs are there to do the heavy lifting for you. In this chapter you learned:

Where to go from here?

Although you will continue to extend this app over the next few chapters, you can access more extensive information on the developer pages for the Google Places SDK for Android (https://stuff.mit.edu/afs/sipb/project/android/docs/guide/topics/location/strategies.html).

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now