Press "Enter" to skip to content

GPS Tracking with Prism + Shiny in Xamarin Forms

In a previous article, I talked about setting up Prism with Shiny in a Xamarin Forms project. Now I will extend on this by adding location tracking support, which is a very common feature in enterprise applications. This article will show you how to do it step by step using Shiny.

Let’s start! 

1. Install the Shiny.Locations package

2-Create a new folder called Delegates and add GPSListener class/interface


This listener will handle our location updates since it has an event handler that gets invoked each time we get a new GPS reading.

3-In the ShinyAppStartup file register GPS listener as a singleton and also register Shiny GPS service.

4-In the ViewModel inject the IGpsManager and the IGpsListener.

The GPSManager has two main methods StartListener and StopListener which start/stop the GPS tracking. To gather location updates will subscribe to GpsListener event called OnReadingReceived that gets called whenever location has changed.

 

5-On iOS project Info.plist add the NSLocationAlwaysUsageDescription permission and enable the location updates background mode.


6-On Android project manifest file be sure to add the ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permissions 

 

 

Check the full source code here.

Happy Shining!!