简体   繁体   中英

Windows Phone Location API

I am developing a location based social networking application and am using a geocoordinatewatcher on high accuracy and a movement threshold of 20m to obtain the user's location. My question is about the frequency of the location fixes. From the documentation, I gather that a movement threshold of 20m simply means that the position changed event is not triggered if the current location is 20m away from the location at the previous position changed event. This suggests that location fixes still happen, but they do not trigger the event handler if <20m. How does the device then decide how often to perform a location fix? Does changing the movement threshold change this in any way? Any extra documentation which I may have missed is welcome!

Thank you!

I think you are wanting to know about how MovementThreshold works and how to set that up.

basically you can say:

public class MyClass
{
      private IGeoPositionWatcher<GeoCoordinate> _geoCoordinateWatcher;

      /// <summary>
        /// Gets the geo coordinate watcher.
        /// </summary>
        private IGeoPositionWatcher<GeoCoordinate> GeoCoordinateWatcher
        {
            get
            {
                if (_geoCoordinateWatcher == null)
                {
                    _geoCoordinateWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
                    ((GeoCoordinateWatcher)_geoCoordinateWatcher).MovementThreshold = 3;
                }
                return _geoCoordinateWatcher;
            }
        }
}

Someplace else you might have

DispatcherTimer currentSpeedTimer = new DispatcherTimer();
            currentSpeedTimer.Interval = new TimeSpan(0, 0, 1);
            currentSpeedTimer.Tick += (sender, e) =>
            {
                if (this.GeoCoordinateWatcher.Position.Location.HorizontalAccuracy < 10)
                {
                    if (DateTime.Now - this.GeoCoordinateWatcher.Position.Timestamp.DateTime > new TimeSpan(0, 0, 2))
                    {
                        CurrentSpeed = 0;
                    }
                    else
                    {
                        CurrentSpeed = double.IsNaN(this.GeoCoordinateWatcher.Position.Location.Speed) ? 0 : this.GeoCoordinateWatcher.Position.Location.Speed;
                    }
                }
            };
            currentSpeedTimer.Start();

It's also worth pointing out that I found working with .NET Reactive Extensions and the IGeoPositionWatcher worked out really well for me.

http://msdn.microsoft.com/en-us/data/gg577609.aspx

To me it sounds like if current location > 20m from previous position fires event..

if there is a way to change the threshold, that seems will trigger differently, however maximum resolution could be 20m as that's usually what satellites have as max res, if I remember correct, not sure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM