1

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?

  • Did you ensure that more than one position was recorded, before trying to access speed? I don't know if speed is automatically managed by the `GeoCoordinateWatcher` but I do know that no speed can be calculated from a single location. – grek40 Jan 05 '17 at 12:46
  • @grek40 I expected to get that automatically! Do I have to store two consecutive location for calculating speed manually like - divide distance between two location by the difference of corresponding time? –  Jan 05 '17 at 13:02
  • Do you retrieve the Location data in a `GeoCoordinateWatcher.PositionChanged` event handler or synchronously in the UI thread? [See here](http://stackoverflow.com/q/9258193/1136211). – Clemens Jan 05 '17 at 13:07
  • @Clemens `coord` is `GeoCoordinate` initialized once in constructor and used in `GetLocationProperty` method. It updates with new location data everytime It is called by `Addellipse `. I did not consider using `GeoCoordinateWatcher.PositionChanged`. So it should be in UI thread I think. –  Jan 05 '17 at 13:18
  • 1
    You should at least try if you actually get valid speed values in a PositionChanged handler. As far as I understood the linked Q/A, Speed may always be NaN when you directly access the Location property (not sure however if that is still true). – Clemens Jan 05 '17 at 13:21
  • @Clemens I have added `watcher.PositionChanged += Watcher_PositionChanged` in constructor, Still I get NaN in `GeoPositionChangedEventArgs e` of `Watcher_PositionChanged` –  Jan 05 '17 at 13:30
  • 1
    And your device is actually moving? – Clemens Jan 05 '17 at 13:30
  • 1
    That's certainly below the threshold to determine a real speed. It has to move continuously for a couple of position fixes. – Clemens Jan 05 '17 at 13:37
  • well, I'll try it in car after an hour @Clemens. Thanks for the information. –  Jan 05 '17 at 13:38
  • 1
    What kind of device is it, does it even have a GPS receiver? Not sure if you get any speed at all when position is detected from WiFi hotspot locations. – Clemens Jan 05 '17 at 13:39
  • It is hp laptop @Clemens –  Jan 05 '17 at 13:40
  • 1
    No GPSR I guess. Without that, determining speed is pointless. You may check the Location's `HorizontalAccuracy` property to get an idea. – Clemens Jan 05 '17 at 13:43
  • It gives `HoriontalAccuracy` as number but NaN for `Course`, `VerticalAccuracy` and `Speed` @Clemens –  Jan 05 '17 at 13:46
  • 1
    Sure, but what is the value of HoriontalAccuracy? – Clemens Jan 05 '17 at 13:47
  • Last time it was 69 @Clemens –  Jan 05 '17 at 13:47
  • 1
    That means you don't have a GPSR. With it, accuracy is a few meters. You can't get speed values without GPS. – Clemens Jan 05 '17 at 13:53
  • As I was moving along the road it added markers along with time almost in right position on the map for 20 km past @Clemens, is it possible without GPSR? –  Jan 05 '17 at 18:20
  • 1
    Not sure what you mean. What is "almost in right position", and was that in a city with a lot of known WiFi hotspots? Without GPS it won't work reliably, at least not outside inhabited areas. – Clemens Jan 05 '17 at 18:49
  • It added markers very close to the streets I have past to come back to home. I am in Dhaka, Bangladesh @Clemens –  Jan 05 '17 at 18:55
  • 1
    If that is what you need. I can't tell you if your application does what you want. – Clemens Jan 05 '17 at 19:00
  • I have tried to add an ellipse on the map after every 10 sec and wanted to get the time and speed from those ellipses as tooltip. Ellipses were added correctly and when I hover over an ellipse I get a tooltip like `8:00 PM NaN`, I expected to get Speed insted of NaN @Clemens –  Jan 05 '17 at 19:11
  • I have understood that. It is what we are talking about all the time. However, I can't tell if the position accuracy you get right now is sufficient, or meets your expectation. Let's stop the discussion now. – Clemens Jan 05 '17 at 19:17

0 Answers0