7/8/2010

This sample shows how you can use Reactive Extensions for .NET to emulate and filter Location Service data. If you are creating a location-aware application but don’t have access to a physical device, you can use this technique to develop using the Windows Phone Emulator.

You will need to install Windows Phone Developer Tools Beta to run this sample. To get started, go to the Windows Phone developer portal.

Using the Sample

This sample uses the following Application Bar buttons:

  • Start and Pause The start button will start the acquisition of data, whether live or emulated data is being used. Once acquisition has begun, the start button is replaced with the pause button, which will stop data acquisition when pressed.
  • Emulation The emulation button, with the star shape, toggles between using live and emulated data. This button is disabled while data acquisition is running. If you are using the device emulator, you should always use emulation because the Windows Phone Emulator does not have any built-in location emulation. If you are using a physical device, you can use either live or emulated data.
  • Record The record button turns on the recording of location data. When you press the button again to turn recording off, the data accumulated while it was on is saved to a file in isolated storage on the device. This is useful if you are developing a location-aware application and have access to a physical device. If a data file has been saved to the device, the sample will use this file for data emulation. If no data file is present in isolated storage, emulation uses the LocationData.txt file included with the solution file and packaged into the compiled application as a resource. This file is simply a list of comma separated latitude and longitude values with a newline between each entry. You can easily replace the contents of this file with your own data.
  • Delete The delete button is only shown when a data file is present on the device. Pressing the button will delete the file. After the file has been deleted, emulation will use the resource file included in the sample solution until another data file is recorded.

The sample interval slider control adjusts the period of time between each sample of the location data stream. This value is read when data acquisition is started, so changing it while data acquisition is running will have no effect.

Status Emulation

The GeoCoordinateWatcher class in the Location Service API allows you to subscribe to StatusChanged events that notify your application of the current state of the Location Service. This sample includes emulation of this behavior. Hard-coded arrays in the source file can be modified to change which status values are returned, and the delay between status values, when emulation is running. You can use this to make sure that your application responds appropriately when location data is or becomes unavailable.