Wednesday, September 22, 2010

GPS Simulator for Windows Phone 7

UPDATE: 12/22/2010 - This project is now posted on codeplex

You want to develop applications that use the GPS on your Windows Phone 7. You may not have a physical device. Or even if you do, sometimes it’s not very convenient to test out your GPS based software by walking around with your phone. To help out with this type of development I created a very simple and crude GPS Simulator to use in your WP7 apps. There are two components to the simulator, the first is a Silverlight desktop hack job application that can be used to construct your route and sample data points. The second is a class that you include in your WP7 app called FakeGps (hmmm wonder where I got that name from?). This class implements the interface IGeoPositionWatcher<T>. This is the same one that actual GPS handler System.Device.Location.GeoCoordinateWatcher implements. This means that your code that handles the events and manipulates the GPS will remain the same.

If your app uses one of those new fangled IOC containers that work on WP7, you can probably get creative and let it handle the instantiation of the GPS handler. Being old school, I’m not convinced that IOC’s really belong on a small phone app (my design pattern for mobile development is KISS) so I create an instance based upon if the debugger is attached, something like:

IGeoPositionWatcher<GeoCoordinate> _watcher;

if (System.Diagnostics.Debugger.IsAttached)
_watcher = new FakeGps();
_watcher = new GeoCoordinateWatcher();

Then just use the _watcher as you normally would.

To get going with the with Simulator, here’s a brief overview of what you need to know.


  1. Silverlight 4 SDK
  2. Bing Maps Silverlight Control SDK


  1. Download the files from here.
  2. Start the solution file in WolfBytes.GpsSimulator
  3. Make sure the project WolfBytes.GpsSimulator.Web is set as your startup project and the page Data.html is set as the start page.
  4. Start the project, you should see a BingMap that looks similar to this.


  1. You can enter the Total Run Time for your route (based upon distance, this will determine your speed).
  2. You can update the Update Period, this is how often the PositionChanged event will fire into your application.
  3. Also you can enter the Pause Before Start. This the number of milliseconds between when the user starts the GPS and the GPS starts sending PositionChanged events.
  4. Finally the XML in the bottom right quarter of your screen will be used to plug your route into your Windows Phone 7 application. (use CTRL+C to copy it after selecting it, then just replace the sample XML in FakeGps with your custom route)
  5. To add route points simply click on the map. Where a push pin is displayed, a way point will be created.

To see how to use the Simulator in your Windows Phone 7 application, just look at the project WolfBytes.GpsClient in the attached solution.

I haven’t spent a ton of time testing this, but it works for my particular problem and rather than keeping it on a shelf until I can perfect it (which will probably never happen) here it is! Enjoy it for what it is…



  1. This comment has been removed by the author.

  2. Great post! I'll take it from here. :)

  3. You've missed a "if (PositionChanged != null)" in line 89 of the fakeGps file...

  4. Hi,

    How can i get the Cellular Emulator to work from the Desktop instead of fom the Emulator?

    I am working on a wpf client -> remote server app using GPRS modem to connect to the server.


    Great post... almost what my doctor ordered..

    I would like to use the Cellular Emulator to setup a test bed for my Continous Integration dev environment..

    Any pointers on how to make this work will be greatly appreciated..

    Thank you.