一、先写下来教训:

如果设置中间值(变量)的时候,一定要注意,什么时候复位(即重新赋值,如以下的(Index)

2020.0720想提交Demo到Github上,但是没上去不知道什么问题

2020.0722问题是登录GitHub的时候输入密码一定要是英文键盘!!
image.png

二、思路

首先我设置的中间变量有
private GMapOverlay gMapOverlay = new GMapOverlay(“Examle”);//保存Train图标的图层
private int Index=0;//用来标记线路的起始点索引
private int maxIndex=0;//标记线路的终点索引
private GMapOverlay currentOverlay;//用来保存中间变量
private GMarkerGoogleExt Train = null;
private List points;//All points of currentOverlay;
System.Timers.Timer t;
最主要的思路就是:
需要利用System.Timers.Timer 中的定时器功能
Timer中的函数Elapsed可以间断性的执行方法。而t.Enabled和t.Stop()都是可以中断Elapsed函数
然而为了让小车Train的位置改变以实现动画
所以需要一个能传递参数的委托
这里就用到了

t = new System.Timers.Timer(10);
t.Elapsed += new System.Timers.ElapsedEventHandler(theout);
t.AutoReset = true;//一次触发还是自动在间隔之后触发事件
t.Enabled = true;//引发Elapsed事件

private void theout(object source, System.Timers.ElapsedEventArgs e)
{
if(maxIndex == 0)//没有设置Maxindex的情况不
{
t.Enabled = false;
return;
}
if(index <= maxIndex-1)
{
Train.Position = GetPointLatLng(index);
index++;
}
else//当index==maxindex的情况停止动画
{
t.Enabled = false;
return;
}
}

三、示例动画:

功能介绍.mp4 (17.36MB)

更加完整的程序在https://github.com/peopleknows/GMapSimulator