Adding Location-based Features Within Your App

In the previous chapter, we learned how to leverage what we already know about the Model-View-ViewModel (MVVM) architectural design pattern and learned how to navigate between each of our ViewModels within our TrackMyWalks application. You learned how to create a BaseViewModel base class that each of our ViewModels will inherit from, as well as how to go about creating the associated C# class files for each of our ViewModels that will data bind to each of the properties defined within our XAML pages.

To end the chapter, you learned how to add ContextActions to your (XAML) content pages, and how to implement the code action events within your code so that you can respond to those actions.

In this chapter, you'll learn how to incorporate platform-specific features within your application, dependent on the mobile platform that is being run, as well as learn how to incorporate the Xam.Plugin.Geolocator NuGet package that you will use in order to create a LocationService Interface and Class, which will include a number of class instance methods that both our iOS and Android platforms will use to obtain current GPS coordinates and hande location updates in the background on the device.

You'll update both the WalkEntryPageViewModel and WalkDistancePageViewModel classes to allow location-based features to happen and create a CustomMapOverlay class that will be used to display a native Map control, based on the platform.

Finally, you'll make some minor changes to the WalkDistancePage.xaml file so that it can use the CustomMapOverlay class and then make changes within the WalkDistancePage.xaml.cs code-behind file to handle location updates, as well as perform location updates in the background to update the native Map control automatically, whenever new location coordinates are obtained.

This chapter will cover the following topics:

  • The benefits of using and implementing platform-specific services within your application
  • Incorporating the Xam.Plugin.Geolocator NuGet package within our shared-core solution
  • Creating and implementing a LocationService class using C#
  • Creating and implementing a CustomMapOverlay class using C#
  • Updating the WalkEntryPageViewModel to use the LocationService class
  • Updating the WalkDistancePageViewModel to use the LocationService class
  • Updating the WalkDistancePage XAML page to use our CustomMapOverlay class
  • Updating the WalkDistancePage code-behind to use the LocationService class
  • Enabling location-based background updates for both our iOS and Android projects
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.80.3