Exemplo n.º 1
0
        /// <summary>
        /// 两两组合去除重复项
        /// </summary>
        /// <param name="sourceList"></param>
        /// <returns></returns>
        private List <SiteDistance> Combination(List <SiteInfo> sourceList)
        {
            List <SiteDistance> destList = new List <SiteDistance>();

            foreach (var site in sourceList)
            {
                foreach (var item in sourceList)
                {
                    if (!site.Equals(item))
                    {
                        SiteDistance distance = new SiteDistance();
                        distance.startCode    = site.orgCode;
                        distance.startName    = site.orgName;
                        distance.startAddress = site.address;
                        distance.startlat     = site.lat;
                        distance.startlng     = site.lng;
                        distance.endCode      = item.orgCode;
                        distance.endName      = item.orgName;
                        distance.endAddress   = item.address;
                        distance.endlat       = item.lat;
                        distance.endlng       = item.lng;
                        destList.Add(distance);
                    }
                }
            }
            return(destList);
        }
Exemplo n.º 2
0
        private void calcDistance(object param)
        {
            var p = (Tuple <int, EventWaitHandle>)param;

            int start = int.Parse(p.Item1.ToString()) * 2000;

            for (int i = start; i < start + 2000; i++)
            {
                if (i + 1 > sorceList.Count)
                {
                    break;
                }
                SiteDistance item = sorceList[i];
                if (item.startCode != item.endCode)
                {
                    Geocoder result = JsonHelper.JsonDeserialize <Geocoder>(BaiduMap.Driving(item.startlat.ToString() + "," + item.startlng.ToString(), item.endlat.ToString() + "," + item.endlng.ToString()));
                    if (result != null && result.result != null && result.result.routes != null && result.result.routes.Count > 0)
                    {
                        item.distance = result.result.routes[0].distance;
                        item.runTime  = result.result.routes[0].duration / 60;
                        item.steps    = GetSteps(result.result.routes[0].steps);
                    }
                }
                else
                {
                    item.distance = 0;
                    item.runTime  = 0;
                }
                item.sn = i;
                deslist.Add(item);
                LogHelper.WriteLog(typeof(Form1), deslist.Count.ToString());
                if (deslist.Count == sorceList.Count)
                {
                    expExcel(deslist);
                }
            }
        }