The location service allows a developer to use GPS devices inside a view model.

Available for
WPF / Silverlight / WP7 / WP7 Mango

Test/Emulation service available: yes

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 timespan and emulate a path.

Last edited Jul 10, 2011 at 1:07 PM by GeertvanHorrik, version 4

Comments

No comments yet.