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:
Declare a private instance of
LocationManager
and obtain a reference in theOnCreateView()
method as follows:LocationManager locMgr; ... public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.Inflate(Resource.Layout.POIListFragment, container...