| Comments

If you’ve been excited about Windows Phone 7 development and the platform being Silverlight for application development, you probably rushed and downloaded all the tools (which are free by the way).  You may have even got the samples from the SDK and noticed the Location services example…but wondered why it doesn’t work.

If you are just getting started, I created some quickstart videos to help you through some of the basics.  You can view them here.

In case you haven’t figured it out: Location services (aka, GPS) is not emulated in the developer tools CTP. 

As you might expect, this makes it difficult to play around with location-based applications.

The API in Windows Phone 7 revolves around the GeoCoordinateWatcher class.  This class is what you would initialize to start listening for events:

   1: GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Low);
   2: watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
   3: watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);

As you can see, this watcher class looks for Status and Position changes.  The status is about the device peripheral itself (initializing, reading, etc.).  Position is more likely what you are interested in and would give you the details of where the device is reading the current location (longitude and latitude).  In the emulator right now the status will always return Disabled.

It’s relatively simple to simulate this, and here’s a really simple mock class for doing so.  Now, note this is not a complete emulation of the Location services APIs for Windows Phone 7 SDK.  This mock is to simply simulate a coordinate location and position changing.  The GeoLocationMock class implements the IGeoPositionWatcher<GeoCordinate> interface for mocking the location service.  There is a Start, Stop, PositionChanged and StatusChanged methods and events (TryStart is implemented, but simply calls Start).  To implement the mock in your application you would instantiate watcher (using above sample) as IGeoPositionWatcher<GeoCoordinate> instead of the GeoCoordinateWatcher specifically.  Here is a sample, and then an explanation:

   1: public partial class MainPage : PhoneApplicationPage
   2: {
   3:     IGeoPositionWatcher<GeoCoordinate> watcher;
   4: }
   5:  
   6: private void StartLocationService(GeoPositionAccuracy accuracy)
   7: {
   8:     if (watcher == null)
   9:     {
  10:         GeoCoordinateEventMock[] events = new GeoCoordinateEventMock[] {
  11:             new  GeoCoordinateEventMock { Latitude=34.4, Longitude=11.2, Time=new TimeSpan(0,0,5) },
  12:             new  GeoCoordinateEventMock { Latitude=31.4, Longitude=21.2, Time=new TimeSpan(0,0,1) },
  13:             new  GeoCoordinateEventMock { Latitude=34.3, Longitude=28.2, Time=new TimeSpan(0,0,2) },
  14:             new  GeoCoordinateEventMock { Latitude=32.4, Longitude=34.2, Time=new TimeSpan(0,0,3) },
  15:             new  GeoCoordinateEventMock { Latitude=31.2, Longitude=37.2, Time=new TimeSpan(0,0,4) },
  16:             new  GeoCoordinateEventMock { Latitude=33.73, Longitude=39.2, Time=new TimeSpan(0,0,5) },
  17:             new  GeoCoordinateEventMock { Latitude=31.87, Longitude=41.2, Time=new TimeSpan(0,0,6) },
  18:             new  GeoCoordinateEventMock { Latitude=11.81, Longitude=42.2, Time=new TimeSpan(0,0,7) }
  19:         };
  20:     
  21:         watcher = new EventListGeoLocationMock(events);
  22:         watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
  23:         watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
  24:     }
  25:  
  26:     watcher.Start();
  27: }

The ‘watcher’ is created using a list of geo location points in this sample above.  Now this could be some web service that does IP address reverse lookup or use hard-coded examples as well like I’ve done above.  Using this mock above and replacing it in the LocationServiceSample in the SDK, here’s what my screenshot shows:

Geo location services mock for Windows Phone 7

So you can see I can start the GPS emulation and simulate subtle position changes (or drastic ones if I wanted, aka maybe a social network map application of sorts).

Hopefully this little snippet will be valuable to play around with or expand upon for your needs.  If anything, you can create some emulation of the behavior temporarily.  The mock object used in a modified LocationServiceSample project can be downloaded here: LocationServiceSampleWithMock.zip.

Hope this helps!

UPDATE: Peter Torr actually had another geo location mock in his MIX10 talk which his code is now available for download.  It is much more comprehensive emulating accuracy, etc.  The above is a simpler approach, but both will get the job done depending on what you really need/want to emulate.


This work is licensed under a Creative Commons Attribution By license.

| Comments

I love my Garmin Nuvi.  As I’ve mentioned before it’s one of the best pieces of technology I own for use, form factor, fun, and coolness factor.  I’ve got the 260 which suits me fine, but if I had to buy a new one, I’d get the 760 now.

One of the weird things is that I keep it on all the time when I’m driving, even if I know where I’m going.  The points of interest (POI) feature is awesome and has helped me discover new places to eat every once in a while.  There are other customizations you can achieve as well like custom voices (I have the UK and Australian female voices on mine to make me feel distinguished) and icons.  All of these are generally announced on the Garmin blog, which is regularly updated with information about Nuvi and all their other product lines.  You can get custom icons from the Garmin Garage location as well.  One thing that I highly recommend is using the POI Loader.

This software enables you to create your own POI waypoints.  You can create them as regular POI waypoints or you can also create “proximity” points that alert you when you are getting near a specific point.  This is generally why I keep it on all the time now.  I’ve created a few of my own POI waypoints for areas of construction that I might forget about, some speed limit changes that I may forget about, etc. 

Recently though, I also found a guy who has organized all photo radar points into a database (you could create your own of course) and sells them for $10 for a 12-month subscription.  Boom, done.  Saves me the time looking them all up and I just have to click and they are uploaded.  The database (which I found on eBay and he has Arizona database as well as other states for photo radar) contains not only fixed points, but also “known” speed trap regular areas.  Just this morning I was on my way to Costco and was alerted to slow down with a notification of a potential speed trap (they weren’t there this morning, but they are regularly there for sure as my wife’s driving record will attest to).  The image (which is the image captured here) displays an icon (notice the little radar dude) as well as a warning banner.  A sound is also audible as well to help you pay attention to the warning.  Very cool.  For $10 I get database updates monthly from this guy (which has 1197 points for Arizona).  Hopefully recent movements by our Arizona state legislature may make me worry less, but until then this helps remind me to drive safe and also keeps me out of trouble (hopefully).

UPDATE: The service I used to use isn't available anymore, but if you want to get red-light/radar points-of-interest (POI) for your GPS device, you can get them here.

The other “customization” I made this week was to purchase the lifetime map subscription.  I’ve been royally burned by lifetime subscriptions in the past, so I was leery on doing this, especially since the lifetime subscription applies only to the particular device.  I knew, however, that I was going to get at least one more map update, so for the extra $30, I get 4 updates per year for the lifetime of my device.  Seemed worth it to me at the time of purchase.  The update was surprisingly huge (1.5GB) but now I’ve got the latest map, updates for “life” and 1197 statewide radar alerts plus my own custom points.

If you have a Garmin device…have fun customizing!


This work is licensed under a Creative Commons Attribution By license.

| Comments

If you are a constant reader of this blog, I suspect you’re a geek as well.  And with most geeks it is generally pretty hard to buy gifts.  We usually buy gadgets when they come out and don’t give much room for ‘wish lists’ for our significant others to shop for us.  As such my house around holidays is usually no gifts for me of substantial surprise…that’s fine by me.

This father’s day was different.  My family got me a portable GPS device.  Specifically the Garmin Nuvi 260.  To be most accurate, my family actually got me a Magellan device but my wife gave it to me with the “I’m not sure if this is a good one so you can get which one you want.”  I love the “you can get” with regard to marriage and purchases…we share the same money don’t we? :-)

After a good amount of research I settled on the Garmin Nuvi line as the best.  Almost every review site I went to had the Garmin Nuvi models at the top of their list.  TomTom was a close second and actually from the experience I liked their physical designs a little better. 

I already have a GPS system in my car, but it is a year 2000 model car, so my GPS screen looks like a mainframe app compared to modern devices…and operates like one as well!  I didn’t think I’d like this idea of the Nuvi because of that, but was I wrong.  Man I turn that thing on to go check the mail.  Honestly I don’t know why, but I’m having so much fun with it!  There was a widescreen model that was about $80 more but had ZERO added features so I opted for the 260 model.  I have NOT been disappointed at all.  The screen is great, the directions are great, re-routing is fast.  I bought the Mexico maps for my device because I go there often.  The Mexico maps came as an SD card I pop in.  I thought this was a little weird because other maps can be downloaded directly into the device…why is Mexico (and some others) different?

This leads me to a little rant.  My Navteq car system wants to charge me $200+ for the map updates to my car.  Garmin - $90.  WTF Navteq!?!?  It’s the same data.  I’ve written to them and asked them why such the difference.  As you would expect: no response.

I used to think about GPS systems in cars and always wanted the in-dash in all my cars.  Never again.  For the cost (walmart.com had the best price for my model at the time of purchase – Best Buy price matched too), you just can’t beat the convenience.  I’ve heard of car companies like Volvo offering a credit voucher instead of in-dash systems.  I must say that is a great idea!  The lack of in-dash is the only thing I don’t like about my device…aesthetically I don’t like the extra thing hanging from my windshield, but the added convenience of taking with me no matter what vehicle I’m in is awesome.  It also has a “walking” mode that routes differently if you are walking.

I couldn’t have possibly asked for a better gift and to-date this has been the best gift I’ve received…and I didn’t even need it!  Bravo family, bravo.  If you are in the market for a GPS unit, check out the Nuvi line.  There are varying features for different models.  I think the 260 is the lowest model I would have went as the one feature I wanted was voice-announced streets (“turn right on Raven” rather than “turn right ahead”).  I don’t much car to integrate my device with as a Bluetooth speakerphone, but there are models that can do that.  Voice commands (available in the 800 series) is something I would have liked, but not at the price differential.  Check out the Nuvi.

I used these sites to help me decide: gpsreview.net and gpsmagazine.com (great buying guide).