Integrating location data with maps

In our previous sections, such as working with the Android Location API and working with the Google Play services Location API, we learned how to obtain location data in different ways. Integrating location data with the map makes it more interesting. Let's finish this chapter with a simple example that has location data integrated with maps.

In this example, I am going to display a marker in my last known location.

The layout code is as follows:

 <?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.MapFragment" />

activity_maps.xml ...

Get Learning Android Google Maps 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.