Showing the User’s Location on a Map

With the requirements behind you, now it is time to enjoy the fruits of your labor and show the user a map. The Maps API includes MapFragment and SupportMapFragment that you can subclass to conveniently handle the work of setting up the MapView and its associated model object, GoogleMap.

Create RunMapFragment, a subclass of SupportMapFragment, in a new file using the code below.

Listing 36.2  Basic RunMapFragment (RunMapFragment.java)

p​u​b​l​i​c​ ​c​l​a​s​s​ ​R​u​n​M​a​p​F​r​a​g​m​e​n​t​ ​e​x​t​e​n​d​s​ ​S​u​p​p​o​r​t​M​a​p​F​r​a​g​m​e​n​t​ ​{​
 ​ ​ ​ ​p​r​i​v​a​t​e​ ​s​t​a​t​i​c​ ​f​i​n​a​l​ ​S​t​r​i​n​g​ ​A​R​G​_​R​U​N​_​I​D​ ​=​ ​"​R​U​N​_​I​D​"​;​

 ​ ​ ​ ​p​r​i​v​a​t​e​ ​G​o​o​g​l​e​M​a​p​ ​m​G​o​o​g​l​e​M​a​p​; ...

Get Android Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.