How to get Speed from GeoCoordinate

505 views Asked by At

I am using GMap.Net to add ellipses as marker on map at runtime. ToolTip property of each ellipse is set to display Time and Speed when Added. Instead of number as speed I get NaN always.

On Timer's elapsed event Addellipse method is called -

void Addellipse(object sender, ElapsedEventArgs e)
{
    App.Current.Dispatcher.Invoke(() =>
    {
        getInfo = GetLocationProperty();
        Ellipse ellipse = new Ellipse()
        {
            Fill = Brushes.Black,
            ToolTip = getInfo.CurrentTime + "\n" + getInfo.CurrentSpeed,
            Height = 7,
            Width = 7
        };

        GMapMarker marker = new GMapMarker(getInfo.CurrentPosition)
        {
            Shape = ellipse,
            ZIndex = int.MaxValue
        };

        MapControl.Markers.Add(marker);
        MapControl.Position = getInfo.CurrentPosition;
    });
} 

GetLocationProperty returns ToolTipInfo

ToolTipInfo GetLocationProperty()
{
    coord = watcher.Position.Location;
    if (!coord.IsUnknown)
    {
        returnlatlon.Lat = coord.Latitude;
        returnlatlon.Lng = coord.Longitude;
        tooltipInfo.CurrentPosition = returnlatlon;
        tooltipInfo.CurrentTime = DateTime.Now.ToShortTimeString();
        tooltipInfo.CurrentSpeed = coord.Speed.ToString();
    }
    return tooltipInfo;
}

here is the ToolTipInfo

public class ToolTipInfo
{
    public PointLatLng CurrentPosition { get; set; }
    public string CurrentTime { get; set; }
    public string CurrentSpeed { get; set; }
}

and my watcher is initialized in this way in constructor

watcher = new GeoCoordinateWatcher();
watcher.TryStart(true, TimeSpan.FromMilliseconds(2000));

How can I get speed?

0

There are 0 answers