我在运行时使用GMap.Net
在地图上添加省略号作为标记。每个椭圆的ToolTip属性设置为在添加时显示时间和速度。而不是数字作为速度,我总是得到NaN。
On Timer的已过时事件Addellipse
方法被调用 -
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
返回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;
}
这是ToolTipInfo
public class ToolTipInfo
{
public PointLatLng CurrentPosition { get; set; }
public string CurrentTime { get; set; }
public string CurrentSpeed { get; set; }
}
我的watcher
在构造函数
watcher = new GeoCoordinateWatcher();
watcher.TryStart(true, TimeSpan.FromMilliseconds(2000));
我怎样才能获得速度?