The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


Mapping with Maps V2

One of Google’s most popular services — after search, of course – is Google Maps, where you can find everything from the nearest pizza parlor to directions from New York City to San Francisco (only 2,905 miles!) to street views and satellite imagery.

Android has had mapping capability from the beginning, with an API available to us as developers to bake maps into our apps. However, as we will see shortly, that original API was getting a bit stale.

In December 2012, Google released a long-awaited update to the mapping capabilities available to Android app developers. The original mapping solution, now known as the Maps V1, worked but had serious limitations. The new mapping solution, known as Maps V2, offers greater power and greater ease of handling common situations, though it too has its rough edges.

Prerequisites

Understanding this chapter requires that you have read the core chapters, along with the chapter on drawables. Also, one of the samples involves location tracking, and another of the samples involves the use of the animator framework.

One section involves the use of Picasso, covered in the chapter on Internet access.

This chapter also makes the occasional reference back to Maps V1 for comparisons, mostly for the benefit of developers already familiar with Maps V1 and looking to migrate to Maps V2. However, prior experience with Maps V1 is not necessary to understand this chapter.

A Brief History of Mapping on Android

Back in the dawn of Android, we were given the Maps SDK add-on. This would allow us to load a firmware-hosted mapping library into our applications, then embed maps into our activities, by means of a MapView widget.

And it worked.

More importantly, from the standpoint of users, the results from our apps were visually indistinguishable from the built-in Maps application available on devices that had the Maps SDK add-on.

This was the case through most of 2009. Eventually, though, the Google Maps team wanted to update the Maps application… but, for whatever reason, the decision was made to not update the Maps SDK add-on as well. At this point, the Google Maps team effectively forked the Maps SDK add-on, causing the Maps application to diverge from what other Android app developers could deliver. Over time, this feature gap became quite pronounced.

The release of Android 3.0 in early 2011 compounded the problems. Now, we needed to consider using fragments to help manage our code and deliver solutions to all screen sizes. Alas, while we could add maps to our fragments, we could only do so on API Level 11 or higher — the fragments backport from the Android Support package did not work with the Maps SDK add-on.

The release of Maps V2 helped all of this significantly. Now we have proper map support for native and backported versions of the fragment framework. We also have a look and feel that is closer to what the Maps application itself supports. While we still cannot reach feature parity with the Maps application, our SDK apps can at least look like they belong on the same device as the Maps application.

More importantly, as of the time of this writing, Maps V1 is no longer an option for new developers. Those who already have Maps V1 API keys can use Maps V1, but no new Maps V1 API keys are being offered. That leaves you with either using Maps V2 or some alternative mapping solution.

Where You Can Use Maps V2

The preview of this section is [REDACTED].

Licensing Terms for Maps V2

The preview of this section was eaten by a grue.

What You Need to Start

The preview of this section is en route to Mars.

The Book Samples… And You!

The preview of this section was abducted by space aliens.

Setting Up a Basic Map

The preview of this section was abducted by space aliens.

Playing with the Map

The preview of this section was whisked away by a shark-infested tornado.

Map Tiles

The preview of this section was fed to a gremlin, after midnight.

Placing Simple Markers

The preview of this section is en route to Mars.

Seeing All the Markers

The preview of this section was whisked away by a shark-infested tornado.

Flattening and Rotating Markers

The preview of this section left for Hollywood to appear in a reality TV show.

Sprucing Up Your “Info Windows”

The preview of this section may contain nuts.

Images and Your Info Window

The preview of this section is in an invisible, microscopic font.

Setting the Marker Icon

The preview of this section is in the process of being translated from its native Klingon.

Responding to Taps

The preview of this section is in the process of being translated from its native Klingon.

Dragging Markers

The preview of this section will not appear here for a while, due to a time machine mishap.

The “Final” Limitations

The preview of this section apparently resembled a Pokémon.

A Bit More About IPC

The preview of this section was stepped on by Godzilla.

Finding the User

The preview of this section was accidentally identified as an Android 'tasty treat' by the Cookie Monster.

Drawing Lines and Areas

The preview of this section was last seen in the Bermuda Triangle.

Gestures and Controls

The preview of this section was stepped on by Godzilla.

Tracking Camera Changes

The preview of this section was last seen in the Bermuda Triangle.

Maps in Fragments and Pagers

The preview of this section will not appear here for a while, due to a time machine mishap.

Animating Marker Movement

The preview of this section will not appear here for a while, due to a time machine mishap.

Maps, of the Indoor Variety

The preview of this section is sleeping in.

Taking a Snapshot of a Map

The preview of this section was lost due to a rupture in the space-time continuum.

SupportMapFragment vs. MapView

The preview of this section is [REDACTED].

About That AbstractMapActivity Class…

The preview of this section was whisked away by a shark-infested tornado.

Helper Libraries for Maps V2

The preview of this section is [REDACTED].

Problems with Maps V2 at Runtime

The preview of this section was fed to a gremlin, after midnight.

Problems with Maps V2 Deployment

The preview of this section was fed to a gremlin, after midnight.

What Non-Compliant Devices Show

The preview of this section was lost in the sofa cushions.

Mapping Alternatives

The preview of this section is being chased by zombies.