UPDATE: 12/22/2010 - This project is now posted on codeplex http://wp7gps.codeplex.com/
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();
else
_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.
Prerequisites
- Silverlight 4 SDK
- Bing Maps Silverlight Control SDK
Usage
- Download the files from here.
- Start the solution file in WolfBytes.GpsSimulator
- Make sure the project WolfBytes.GpsSimulator.Web is set as your startup project and the page Data.html is set as the start page.
- Start the project, you should see a BingMap that looks similar to this.
- You can enter the Total Run Time for your route (based upon distance, this will determine your speed).
- You can update the Update Period, this is how often the PositionChanged event will fire into your application.
- 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.
- 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)
- 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…
-twb
This comment has been removed by the author.
ReplyDeleteGreat post! I'll take it from here. :)
ReplyDeleteYou've missed a "if (PositionChanged != null)" in line 89 of the fakeGps file...
ReplyDeleteHi,
ReplyDeleteHow 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.
Hi,
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.