O'Reilly logo

Android Programming: The Big Nerd Ranch Guide by Brian Hardy, Bill Phillips

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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​; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required