Using Rx to fine tune moving maps in Windows Phone 7

Bing Maps ScreenI’ve been constantly impressed with how productive the development environment for Windows Phone 7 is. Having access to most of .NET 3.5, along with Reactive Extensions for .NET (Rx) allows us to produce incredibly elegant code for common scenarios.

In the MyTours application I’m developing, I wanted to show the user their location on a map, and have the map track along with their movement. Thing is, I didn’t want the entire map to move and redraw constantly, so what I wanted to do was:

  • Move the pointer showing the user’s location every half second to wherever the phone moved; BUT
  • Only move the map itself when the user has moved more than, say 100m.

The actual movement is incredibly simple to do. I have a map control with the Center bound to MapCenter in the ViewModel, and a custom Pushpin (just two concentric circles) with the Location bound to a “YouAreHere” property in the ViewModel. You can see these bindings in the highlighted lines:

<m:Map Name="TourMap"
CredentialsProvider="{StaticResource BingMapCredentials}"
Center="{Binding MapCenter, Mode=TwoWay}"
ZoomLevel="{Binding ZoomLevel, Mode=TwoWay}" >
    <m:MapLayer x:Name="YouAreHereLayer">
            <m:Pushpin x:Name="targetPin" Location="{Binding YouAreHere}">
                        <Grid Name="ppLocation" Width="20" Height="20" Visibility="{Binding IsTracking,Converter={StaticResource boolToVisibilityConverter}}">
                            <Ellipse Fill="Red" Width="20" Height="20" HorizontalAlignment="Center"  VerticalAlignment="Center" Opacity="0.2"  />
                            <Ellipse Fill="Red" Width="4" Height="4" HorizontalAlignment="Center"  VerticalAlignment="Center" Opacity="0.8"  />

(There’s more stuff on the map, but I’ve simplified it for this demo)

YouAreHere and MapCenter are just plain old notifying properties (using a little helper method in my ViewModelBase that fires PropertyChanged). They are properties of the view model that is the DataContext of the page holding the map. I use Caliburn Micro to wire my views (xaml files) to view models (c# objects).

private GeoCoordinate _mapCenter;
private GeoCoordinate _youAreHere;

public GeoCoordinate MapCenter
    get { return _mapCenter; }
    set { SetNotifyingProperty(() => MapCenter, ref _mapCenter, value); }

public GeoCoordinate YouAreHere
    get { return _youAreHere; }
    set { SetNotifyingProperty(() => YouAreHere, ref _youAreHere, value); }

Then when the user wants to start tracking their location, I use some sexy Rx goodness to do most of the heavy lifting:

public void ShowMyLocation()
    if (_isTracking)

    _watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);

    // sample every half second
    var sampledPositionEvents =

    // move the YouAreHere pin on every half-second result
        args => YouAreHere = args.Position.Location);

    // change the map center on 100m+ changes
        args => MapCenter.GetDistanceTo(args.Position.Location) > 100).Subscribe(
        args => MapCenter = args.Position.Location);

    // just old fashioned event handling for status changes
    _watcher.StatusChanged += StatusChanged;

Explaining some of the highlighted lines above for clarity:

  • Line 10 borrows some code that generates an event stream from the Phone’s GeoCoordinateWatcher.
  • Line 11 uses the built-in Rx Sample method to only return a result every 500 milliseconds.
  • Lines 14 and 15 subscribe to the half-second samples and always update the users location indicator on the map.
  • Line 19 further filters down the half-second samples and only returns those samples where we are 100 metres or more from our MapCenter.
  • Line 20 subscribes to those 100m+ events and moves the map center (which, in turn means newer samples are no longer 100m away).

Of course we could have coded this all with good old fashioned event handlers and timers, but it’s nowhere near as compact or sexy looking.

Thinking about fitness

I’ve been thinking hard about getting fit. One can’t just rush into these things. I could just throw on some shoes and start running, but where would all the data go? Speed, distance, heart rate: all this information being pumped out with every step, going to waste.

I tried and failed with a few approaches. Manual exercise recording with isn’t granular enough. I did have some success with Runkeeper on the iPhone, but battled with GPS sensitivity, and ironically (if you’ve been following me on Twitter), lack of multitasking – not to mention the inability to track heart rate information. Carrying some bulky GPS device in addition to my iPhone isn’t an option.

Not a giant wrist computer

Forerunner 405Chris, quite the unreasonably fit geek, suggested a Garmin Forerunner. I remembered these as bulky wrist-computers that even the most unabashed geek would have trouble living down. Imagine my surprise when the Garmin Forerunner 405 arrived on my doorstep.

The 405 looks nothing like a GPS device. I’d be quite happy wearing it as a regular sports watch, if it weren’t for constant recharging required due to the 2-week standby time. Kick it into full GPS training mode, and the battery will be chewed up in 10 hours. It does seem quite power hungry, but I guess this is fine for all but the most advanced endurance athletes.

When you consider what Garmin have packed into the 405, you can understand why it needs so much power. At its heart the 405 is a 1000-lap stopwatch with a sensitive GPS receiver that will track your speed and distance. The watch supports the ANT+ protocol, so any compatible devices can be paired with the device to add their own data. It comes with a heart monitor as standard, and you can purchase add a cadence meter if you’re a cyclist.

Using the touch-sensitive bezel, you can pull up any information during training in the form of customisable screens. Pretty much any combination of speed, pace, distance and heart rate are available. There’s also a “virtual partner” mode that tells you if you are behind or ahead of a set pace or previous recording.

Online Magic

Garmin Connect ScreenshotWhen you get back to your PC, the real magic happens. After pairing (yes, Bluetooth users will find the process familiar) with the ANT+ USB stick, the Garmin 405 will send its information up to the Garmin Connect service.

This is more like it. There’s all that data I was talking about, laid out in gorgeous infographics. You can see a track of your run, along with speed, elevation, and heart rate. You can even play back your training event and see how these measurements correlate.

Regardless of your measure, I am not an athlete. I have heard that these bizarre humans do in fact use this information to improve their ability to inflict pain on themselves. You may have felt like you were going to die running up that hill, but if the stats show you that you had 10 more bpm in your heart muscle, then you’d better go out there again and punish yourself.

Get one

You can get the Garmin Forerunner 405 for around NZ$450 from a number of different places, including here and here.

WIN: Navman, Bluetooth Hands Free Giveaway

Apologies for the web server issues earlier. The wonderful guys at SiteHost have solved my problem and everything should be swimming along now. If you had any trouble entering, try again just in case – I’ll manually remove duplicates.

You saw the reviews on TVNZ Breakfast, now you can have the products. Each of these devices will let you use your Bluetooth phone hands-free in your car, saving you from breaking the law come November.

You can enter once for the entire draw, and three separate winners will be drawn.

Yep, that’s almost $1,500 worth of prizes. Don’t say I don’t love you guys.

Entries are now closed. Here are the results. If you’re a winner, you should have an email now.


  • One entry per person.
  • Entries only valid using the entry form above.
  • Entries limited to New Zealand residents only (sorry guys, the postage will kill me).
  • The items are brand new, but may have been opened and reviewed for this website and TVNZ.
  • Entries close Sunday 20 September 2009 at 8:00pm (NZ time).
  • Winners will be contacted by email.

Navman MY500XT: Bouquets and Brickbats

It’s no secret that I found the Navman S200 appallingly irritating. So you can imagine my trepidation when I was accosted by a charming PR person (do they come in other flavours?), bubbling about the new Navman range, now with integrated traffic information for New Zealand. Casting aside my black mood towards GPS units, I grudgingly accepted the offer of a review unit.

Navman MY500XT intro stickerFirst big change: the unit comes with a giant sticker over the screen, advertising the solution to one of the more irritating UI issues: lack of responsiveness. You can see the sticker at right. It informs you that you can either use the slidey-glidey menus, or turn on the more basic “tap-touch”. The ironic thing is that the screen on the MY500XT is massively more responsive than the S200, so the slidey-glidey menus actually work quite well. Bouquets! Having said that, I can see that the tap-touch menus would work better when on the move (not that anyone uses a GPS device when on the move, right?).

Navman have also removed the inane and utterly pointless “don’t click there, click here!” video on startup. It has been replaced by a nice clear tutorial, with a big “never, ever show me this tutorial again” option on the first page. Bouquets!

The map display in general appears to be tidied up. Road names appear clearly and almost all upcoming roads are named. This is important when you’re running in non-routing mode and looking for an upcoming side road. I loved the way TomTom did this, but Garmin do it very, very badly. Navman’s new software is right up there with TomTom. Bouquets!

I’ve yet to have a proper play with the traffic options in anger, but I’ve seen a demo and I’m impressed. All the bits and bobs are there, including options to route around bad traffic or road closures. The traffic data itself is of cours sourced from Geosmart and completely out of Navman’s control, but the display and layout of traffic info is done well. Bouquets!

Now the big, aching brickbat. Whoever designed the mounting bracket and power plug arrangement on this device is an intellectual dwarf of the lowest order. They should be locked in a padded cell covered with Navman mounting brackets and forced to plug and unplug MY500XTs continuously for the rest of their living days.

Navman mounting 1Navman mounting 2Navman mounting 3

Look closely. There is no possible way to plug the Navman in before mounting it on the bracket. None. Am I being picky? How about you sit in your car with the MY500XT on its bracket on the window, where you can’t see the mini-USB socket on its underside, and try plugging it in. Do that every. single. time. you hop in your car. 👿 👿 👿

Navman, please, if you are reading this: open every single MY500XT box you have in your warehouse, remove the power cable, and replace it with one that bends the other way. It’s a simple fix. I’m begging you.

Conclusion: lovely device software. Pity about the lack of attention to detail.

TomTom for iPhone Review

Correction: the TomTom application will work with the iPod Touch if there is an external GPS receiver. Since the TomTom cradle includes an external GPS receiver, TomTom will work on the iPod Touch when mounted in the cradle.
Update from TomTom’s PR company: the cradle will be available in New Zealand “in a couple of months”. The cradle does not enable GPS to work with the iPod touch.

TomTom NavigatingIf you have a dedicated in-car GPS unit, and don’t frequently travel to unfamiliar destinations, I’m betting the unit is in your glove box, where you left it for security about 3 months ago and haven’t bothered to re-mount it. Mine is.

Sure, I use the device when I’m travelling out of town or to an address that I don’t know. The rest of the time, I honestly wonder why I bought the device at all. That’s not entirely true: I know that I bought it because it makes the car feel like an aeroplane or a spaceship. VROOM!

One thing that does live on my dashboard any time I’m in the car is my iPhone. It slots into a snug holder, and plugs into the car stereo’s AUX input. Coupled with a nice Bluetooth handsfree kit, this means I can listen to music or podcasts, and take calls easily. When I leave the car, it goes in my pocket, as my main phone and mp3 device.

I think TomTom secretly understand the shortcomings of a dedicated in-car GPS. A one-use device. Yes you’ll find that higher-end models have additions like Bluetooth handsfree and FM transmitters, but quite frankly the ones I’ve tested have been poor.

Rather than battle to add more features to their dedicated GPS units, TomTom have taken the alternative route: add GPS to your existing all-in-one device. TomTom for iPhone (iTunes link) looks and feels like a dedicated GPS unit, but it is running as an application on your iPhone. It uses the internal GPS chip in your iPhone 3G or 3GS, and it just works.

The app fires up in seconds on a 3GS, and gets a GPS lock immediately under clear skies. I had no issue with reception. The app is a mix of familiar TomTom presentation (the summary bar below the screen) and iPhone usability (scrolling menus, contacts integration). You can listen to music while navigating, and the app saves state (destination settings etc.), when switching to other apps or taking calls. Turn directions are loud and clear, and even in a gen-yoo-inn keewee accint for the New Zealand version.

TomTom is also releasing a dedicated cradle that apparently has an external GPS receiver for better reception. I’m unsure if this enables navigation on a non-GPS device like the iPod Touch. In my experience, any iPhone cradle will be fine.

The one thing missing from TomTom for iPhone (in New Zealand at least) is traffic. TomTom does have “IQ Routes” which use historical travel time data to determine best routes, but not true realtime traffic info. I’ve got my hands on the new Navman MY500XT, which does do realtime traffic, so will be interested to see how it helps.

Conclusion: if you have an iPhone 3G or 3GS and are thinking about getting in-car GPS: don’t. Just get a cheap cradle and the $120 TomTom app.

Gallery of TomTom UI Shots: