Beispiel #1
0
        /// <summary>
        /// 计算坐标点的距离
        /// </summary>
        /// <param name="begin">开始的经度纬度</param>
        /// <param name="end">结束的经度纬度</param>
        /// <returns>距离(公里)*1000=米</returns>
        public static double GetDistance(Poin begin, Poin end)
        {
            double lat = begin.RadLat - end.RadLat;
            double lng = begin.RadLng - end.RadLng;

            double dis = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(lat / 2), 2) + Math.Cos(begin.RadLat) * Math.Cos(end.RadLat) * Math.Pow(Math.Sin(lng / 2), 2)));

            dis = dis * EARTH_RADIUS;
            dis = Math.Round(dis * 1e4) / 1e4;

            return(dis * 1000);//乘以1000就是 米数 计算出来的原本是 公里
        }
Beispiel #2
0
        /// <summary>
        /// 获得经纬度
        /// </summary>
        /// <returns></returns>
        public ActionResult GetLocal()
        {
            JsonSMsg msg = new JsonSMsg();

            string lo = Request["LO"];

            string ln = Request["LN"];

            string code = Request["CODE"];

            List <BCJ_CITY> citys = new List <BCJ_CITY>();


            //如果城市编码是空表示顾客自己定位刚进入页面需要加载城市等信息
            if (string.IsNullOrEmpty(code))
            {
                TenAPI model     = Utility.GetLocal(lo, ln);
                string citymodel = model.result.formatted_address;

                logger.Info(citymodel + "====" + lo + "===" + ln);

                //citys.AddRange(_book.GetCity());
                citys.AddRange(_book.GetAvalibleCity());

                BCJ_CITY one = citys.Where(a => citymodel.Contains(a.CITY_NAME)).ToList().FirstOrDefault();

                code = one == null ? "110100" : one.CITY_CODE;
            }

            //加载门店列表
            List <BCJ_STORES_EX> stores = _bcjStore.GetStoresByCityCode(code);


            //如果不是定位则计算距离城市中心点的位置
            foreach (BCJ_STORES_EX storeM in stores)
            {
                Poin beigin = new Poin(double.Parse(ln), double.Parse(lo));
                Poin end    = new Poin(double.Parse(storeM.LONGITUDE), double.Parse(storeM.LATITUDE));
                storeM.Distance = Utility.GetDistance(beigin, end).ToString();
                storeM.NAME     = storeM.NAME.Trim();
            }


            msg.Data = new
            {
                CIRY_CODE = code,
                CIRYS     = citys,
                STORES    = stores.OrderBy(a => a.Distance)
            };
            return(Json(msg));
        }
Beispiel #3
0
        /// <summary>
        /// 获得经纬度
        /// </summary>
        /// <returns></returns>
        public dynamic GetLocalStore(dynamic arg)
        {
            MapRequest request = base.BindObject <MapRequest>();
            string     lo      = request.LO;
            string     ln      = request.LN;
            string     code    = request.CODE;

            List <BCJ_CITY> citys = new List <BCJ_CITY>();


            //如果城市编码是空表示顾客自己定位刚进入页面需要加载城市等信息
            if (string.IsNullOrEmpty(code))
            {
                TenAPI model     = Utility.GetLocal(lo, ln);
                string citymodel = model.result.formatted_address;

                logger.Info(citymodel + "====" + lo + "===" + ln);

                citys.AddRange(_hmjCommonService.GetCity());

                BCJ_CITY one = citys.Where(a => citymodel.Contains(a.CITY_NAME)).ToList().FirstOrDefault();

                code = one == null ? "110100" : one.CITY_CODE;
            }

            //加载门店列表
            List <BCJ_STORES_EX> stores = _hmjCommonService.GetStoresByCityCode(code);


            //如果不是定位则计算距离城市中心点的位置
            foreach (BCJ_STORES_EX storeM in stores)
            {
                Poin beigin = new Poin(double.Parse(ln), double.Parse(lo));
                Poin end    = new Poin(double.Parse(storeM.LONGITUDE), double.Parse(storeM.LATITUDE));
                storeM.Distance = Utility.GetDistance(beigin, end).ToString();
                storeM.NAME     = storeM.NAME.Trim();
            }
            return(ResponseJson(false, "添加失败", new
            {
                CIRY_CODE = code,
                CIRYS = citys,
                STORES = stores.OrderBy(a => a.Distance)
            }));
        }