Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Talk:Implementing GeoCordinateWatcher as a Reactive Service

From Wiki
Jump to: navigation, search


Hamishwillee - Thanks for this, and the translation

Hi Paulo

Thanks very much for this article and for its translation Implementando O GeoCordinateWatcher Como Um Servico Reativo. I have made a minor modification to this - improving the abstract and introduction so it has a better structure. In particular "Rx" is not a very good term to use in the Abstract (or elsewhere) before definition because it is much overloaded (ie Receiver etc). I like how you've presented this. We can have a specific category for RX if you think there will be more topics on this - but if not, leave it in General Programming. If you do need such a category, please make it the full name "Reactive Services" or "Windows Phone Reactive Services".

The one main open issue is your image. The wiki cannot display remote images in a URL. Can you therefore upload the image (assuming you have rights to) and link to that instead.



hamishwillee 02:47, 21 January 2013 (EET)

Hamishwillee - Compare to await ...

As WP8 added new support for asynchronous programming using await etc., is it worth discussing briefly where you would use Rx and where you would use the newer methods?

hamishwillee 02:50, 21 January 2013 (EET)

Paulo.morgado - Reactive (Rx.) vs. Async

Rx is about handling streams of events.

async/await is about handling request/reply asynchronous calls while writing synchronous-like code.

I'll have to write something about this soon.

Hamishwillee - Thanks for the clarification

I'm sure an example would make it clearer to me. It is obviously your call about what is appropriate in this article!

Thanks again for contributing, this does look useful.

hamishwillee 03:26, 21 January 2013 (EET)

Novanisphone - Geolocator

Hi I was wondering if you can give us a sample like you did for Geocoordinatewatcher on Geolocator. I am having a very difficult time subscribing to its event. Thank you.

novanisphone (talk) 00:22, 5 February 2014 (EET)

Paulo.morgado - Geolocator


What difficulties are you running into?

paulo.morgado (talk) 01:17, 5 February 2014 (EET)

Novanisphone - Geolocator

Here is the code I have written:

           gL = new Geolocator();
           gL.DesiredAccuracy = PositionAccuracy.High;
           var query = Observable.FromEventPattern<PositionChangedEventArgs>(gL, "PositionChanged").Select(i => i.EventArgs.Position).DistinctUntilChanged();
           var evt = query.Subscribe(
           a =>
               if (App.myLoc == null)
                   App.myLoc = new MyLocationInfo();
               App.myLoc.myCurrentLocation = a.Coordinate;

The problem I have is that whateve is in the subscribe never seems to fire. And I can't use observeon(deployment.current.dispatcher) either. I am using using System.Reactive; using System.Reactive.Linq;

as suggested by MSDN.

novanisphone (talk) 07:42, 5 February 2014 (EET)

Paulo.morgado - Paulo.morgado - Geolocator

Have you read the remarks on the PositionChanged event?

You might also look at Updating your Windows Phone Location code to use WinRT.

paulo.morgado (talk) 13:33, 5 February 2014 (EET)

Paulo.morgado - Geolocator

I think I got what your problem is. It's with the event subscription.

You're trying to subscribe to an event named **PositionChanged** with the **EventHandler<PositionChangedEventArgs>**, which doesn't exist. Aren't you getting an exception because of this?

Try this:

           var query = Observable
               .FromEvent<TypedEventHandler<Geolocator, PositionChangedEventArgs>, PositionChangedEventArgs>(
                   handler => this.geolocator.PositionChanged += handler,
                   handler => this.geolocator.PositionChanged -= handler)
               .Select(e => e.Position)

paulo.morgado (talk) 03:17, 6 February 2014 (EET)

Novanisphone -

So here is what happened so far. Your suggestion is the one that raised an exception. Mine worked ok. However on mine, I had to add Deployment.Current.Dispatcher.BeginInvoke in order to display messagebox within Subscribe method.

novanisphone (talk) 04:35, 6 February 2014 (EET)

Paulo.morgado - Geolocator

Exceptions aren't all equal. What is the exception you're getting?

You wouldn't need the Deployment.Current.Dispatcher if you had called ObserveOnDispatcher() as I did on my example.

paulo.morgado (talk) 09:19, 6 February 2014 (EET)

Novanisphone -

That is right. Good point.

novanisphone (talk) 01:43, 7 February 2014 (EET)

Paulo.morgado - Exposing the Geolocator as a Reactive Service

It's still in draft and not fully completed, but I've started an article with a reactive implementation of the Geolocator:

paulo.morgado (talk) 02:57, 21 February 2014 (EET)