O'Reilly logo

Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android by Michael Eierman, Jakob Iversen

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

Get Coordinates from the Map

The final way to get the GPS coordinates of your device’s location is through the map object. The map has built-in methods that access the sensors without writing any code to access the sensors. This makes things easier because all sensor management is handled by the map. The drawback is that you must display a map in the layout to use these features.

Return to activity_contact_maps.xml and delete all the widgets you put in the layout except the navbar. Be sure to leave the root RelativeLayout. Next, add the MapFragment. The MapFragment is not available in the Palette, so it must be added through XML. Refer to Listing 7.6 to do this.

Listing 7.6 MapFragment XML

<fragment    android:id= ...

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