LocationService
The ILocationService allows a developer to use GPS devices inside a view model.
It is important that the service must be started and stopped to retrieve values
Framework | Supported |
---|---|
WPF | |
Silverlight 4 | |
Silverlight 5 | |
Windows Phone 7 | |
Windows Phone 8 | |
Windows RT | |
Test/emulation service |
Starting the service
The GPS service needs to be started and stopped. To start the GPS service, use the following code:
var locationService = GetService<ILocationService>(); locationService.LocationChanged += OnCurrentLocationChanged; locationService.Start();
The service will raise the LocationChanged event when a new location becomes available.
Stopping the service
It is required to stop the service when it is no longer needed. The service can be stopped using the following code:
var locationService = GetService<ILocationService>(); locationService.LocationChanged -= OnCurrentLocationChanged; locationService.Stop();
Emulating GPS without device
It is possible to emulate GPS without actually owning a Windows Phone 7 or emulate data in the emulator. To accomplish this, it is required to use the Catel.MVVM.Services.Test.LocationService class. This class can be used in the following way:
Test.LocationService service = (Test.LocationService)GetService<ILocationService>(); // Queue the next location (and then wait 5 seconds) var locationTestData = new LocationTestData(new Location(100d, 100d), new TimeSpan(0, 0, 0, 5))); service.ExpectedLocations.Add(locationTestData); // Go to the next location manually service.ProceedToNextLocation();
It is also possible to enqueue lots of coordinates with a time span and emulate a path.