Book Image

Xamarin Mobile Application Development for Android, Second Edition

Book Image

Xamarin Mobile Application Development for Android, Second Edition

Overview of this book

Table of Contents (18 chapters)
Xamarin Mobile Application Development for Android Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding location services to POIApp


In POIApp, we have the following two different scenarios for requesting location updates:

  • In the POI list, we need to calculate the distance of each of the listed POIs. In this scenario, we want to request location change notifications on an ongoing basis and use the most current location to calculate the distance.

  • In POIDetailFragment, we would like to request the current location when adding a new POI. In this scenario, we would want to request a single location change notification.

Adding location services to the POI list

Now that we have some idea of how to add location services to an app, let's add location services to POIListFragment as follows:

  1. Declare a private instance of LocationManager and obtain a reference in the OnCreateView() method as follows:

    LocationManager locMgr;
    ...
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
      View view = inflater.Inflate(Resource.Layout.POIListFragment, container...