Example #1
0
        /// <summary>
        /// 两两组合去除重复项
        /// </summary>
        /// <param name="sourceList"></param>
        /// <returns></returns>
        private static List <SiteDistance> Combination(List <SiteInfo> sourceList)
        {
            List <SiteDistance> d = 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;
                        d.Add(distance);
                    }
                }
            }
            return(d);
        }
Example #2
0
        private static void calcDistance(object param)
        {
            var p = (Tuple <int, EventWaitHandle>)param;
            //Console.WriteLine(Thread.CurrentThread.Name + ": Begin!");
            int start = int.Parse(p.Item1.ToString()) * pageSize;

            for (int i = start; i < start + pageSize; i++)
            {
                if (i + 1 > sourceList.Count)
                {
                    break;
                }
                SiteDistance item = sourceList[i];
                if (item.startCode != item.endCode)
                {
                    #region 百度部分
                    //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);
                    //}
                    #endregion
                    string      result   = GaodeMap.Truck(item.startlng.ToString() + "," + item.startlat.ToString(), item.endlng.ToString() + "," + item.endlat.ToString(), "3");
                    GaodeResult gdResult = JsonHelper.JsonDeserialize <GaodeResult>(result);
                    if (gdResult != null && "0".Equals(gdResult.errcode))
                    {
                        item.distance = gdResult.data.route.paths[0].distance;
                        item.runTime  = gdResult.data.route.paths[0].duration / 60;
                        item.steps    = GetSteps(gdResult.data.route.paths[0].steps);
                    }
                }
                else
                {
                    item.distance = 0;
                    item.runTime  = 0;
                }
                item.sn = i;
                destList.Add(item);
                Console.WriteLine("当前运算进度:" + ((decimal)destList.Count / sourceList.Count * 100).ToString("#0.00") + "%-----》正在获取" + item.startName + "===" + item.endName + "信息\n");
            }
            p.Item2.Set();
        }