Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Using the geolocator on Windows Phone 8

Back to Forum: Tech Off
  • User profile image
    Mauricio Feijo

    I have been writing some code using the WP8 geolocator and have been finding many challenges  as I go, and as this is all somewhat new at the time this is being written, I thought I'd open a forum to share those with  others.

    Here is one that I still haven't fully resolved: Should I use the Geolocator.PositionChanged event handler to update location or should I use the Geolocator.GetGeopositionAsync async method (using await to call) and test if the location changed by a given threshold before I make updates, to a map, for example?

    I initially went for the direct call method. It worked well but seemed counter intuitive when I realized I could simply use an event handler and define the DesiredAccuracy to filter only good reads.

    I then modified my code to use the event handler. All worked well, except that the reads are sporadic. Regardless of setting Geolocator.ReportInterval or the Geolocator.MovementThreshold the event fires at will.

    I am working on this and will post developments.

  • User profile image
    Dr Herbie

    @Mauricio Feijo: Note that I haven't used the new WP8 GPS library, but I have used the older WP7 libraries.

    I would go with the PositionChanged event as it will give you a more optimised use of the GPS data.  Use the MovementThreshold property to set the desired accuracy for the position changed (e.g. 'Give me a position every time it passes 100m from the last position').  This will let the library take care of the details and makes your own code simpler.

    The problem is that GPS readings are not always as accurate as you might expect and you can get large 'spikes' that will suddenly give you coordinate in the middle of a field half a mile away;  I ended up using the position changed with a threshold plus some code in the handler to filter out these odd large movements (by calculating the distance between the new coordinate and the last coordinate and filtering out anything over 150 meters away (appropriate for a walking app).




Conversation locked

This conversation has been locked by the site admins. No new comments can be made.