示例#1
0
        public ActionResult BranchList()
        {
            IList <Branch> listBranch = _branchService.GetALL().Where(b => b.Status == 1).ToList();
            string         point      = RQuery["point"];
            string         _X         = "0.00"; //经度
            string         _Y         = "0.00"; //纬度

            if (!string.IsNullOrWhiteSpace(point))
            {
                string[] arrPoint = point.Split(',');

                if (arrPoint.Length > 1)
                {
                    _X = arrPoint[0]; //经度
                    _Y = arrPoint[1]; //纬度
                }
            }

            ViewBag.longitude = _X;
            ViewBag.latitude  = _Y;
            //计算距离
            IList <BranchDTO> listBranchDTO = new List <BranchDTO>();

            foreach (Branch branch in listBranch)
            {
                BranchDTO dtoBranch = new BranchDTO(branch);
                dtoBranch.Distance = DistanceHelper.GetDistance(double.Parse(_Y), double.Parse(_X), double.Parse(dtoBranch.Latitude ?? "24.737727"), double.Parse(dtoBranch.Longitude ?? "118.656141"));
                listBranchDTO.Add(dtoBranch);
            }

            if (listBranchDTO != null && listBranchDTO.Count > 0)
            {
                listBranchDTO = listBranchDTO.OrderBy(b => b.Distance).ToList();
            }

            return(View(listBranchDTO));
        }