Click here to Skip to main content
13,043,491 members (50,943 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 22 Jan 2013

Using the GeoCoordinateReactiveService

, 28 Jan 2013
Rate this:
Please Sign up or sign in to vote.
How it can be used in a simple application

Having created an Rx wrapper over the GeoCoordinateWatcher in a previous post, in this post, I’ll demonstrate how it can be used in a simple application.StatCounter

The application will display the status of the service, the position and the distance traveled.

For this simple application, the service will be exposed as a singleton property of the App class:

public partial class App : Application
    // ...

    public static IGeoCoordinateReactiveService GeoCoordinateService { get; private set; }

    public App()
        // ...


        // ...

    // ...

    private void InitializePhoneApplication()
        // ...

        GeoCoordinateService = new GeoCoordinateReactiveService();

        // ...

    // ...

Getting the status of the service is very simple. It just requires subscribing to the StatusObservable. Since we want to display the status, we need to observe it on the dispatcher before:


For the position, we do the same with the PositionObservable:


The distance traveled would seem a bit more complicated because we need to keep track of the last position and calculate the distance traveled on every position change. But this is where the Rx excels with its query operators. If we combine the position observable with the position observable having skipped one position with the zip operator, we end up with an observable with the current and previous position. And if we apply a selector, we get the traveled distance:

        (p1, p2) => p1.Location.GetDistanceTo(p2.Location))

You can find the complete implementation of the service and application here.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Paulo Morgado
Software Developer (Senior) Paulo Morgado
Portugal Portugal

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 28 Jan 2013
Article Copyright 2013 by Paulo Morgado
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid