示例#1
0
 /// <summary>
 /// 获取解析结果
 /// </summary>
 /// <returns></returns>
 public GeocoderResultModel GetGeocoderResult()
 {
     try
     {
         string str = RequestData.GetResponseStream(Url);
         GeocoderResultModel model = new  GeocoderResultModel();
         if (!string.IsNullOrEmpty(str))
         {
             if (ParamModel != null)
             {
                 if (ParamModel.output.ToString().ToLower() == "xml")
                 {
                     model = Serializer.FromXml <GeocoderResultModel>(str);
                 }
                 else
                 {
                     model = Serializer.FromJson <GeocoderResultModel>(str);
                 }
             }
         }
         return(model);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#2
0
        public ActionResult UpdateScene(SceneUpdateModdel model)
        {
            var result = new StandardJsonResult <bool>();

            result.Try(() =>
            {
                if (!ModelState.IsValid)
                {
                    throw new KnownException(ModelState.GetFirstError());
                }
                if (model.EndDate < model.BeginDate)
                {
                    throw new KnownException("结束时间需要大于开始时间");
                }
                if (model.SceneTypestring != "")
                {
                    model.SceneType = model.SceneTypestring;
                }
                var dto = (ScenesDto)model;
                if (dto.Address == null || dto.Address.Equals(""))
                {
                    dto.LatitudeAndLongitude = "";
                }
                else
                {
                    Geocoding gd = new Geocoding(new GeocodingParam()
                    {
                        address  = dto.Address,
                        ak       = "",
                        callback = "",
                        city     = "",
                        output   = "json",
                        sn       = ""
                    });
                    GeocoderResultModel gdresult = gd.GetGeocoderResult();
                    double[] ss = GetLocation(gdresult);
                    dto.LatitudeAndLongitude = ss[0] + "|" + ss[1];
                }
                if (model.RoleWorkers == null)
                {
                    dto.Wokers = new List <GroupedUser>();
                }
                else
                {
                    List <GroupedUser> list = new List <GroupedUser>();
                    foreach (var u in model.RoleWorkers)
                    {
                        list.Add(u);
                    }
                    dto.Wokers = list;
                }
                result.Value = _sceneService.UpdateScene(dto);
            });
            if (!result.Value && result.Message == null)
            {
                result.Message = "没有内容更新";
            }
            return(result);
        }
 static private double[] GetLocation(GeocoderResultModel model)
 {
     double[] location = new double[2];
     if (model.result != null)
     {
         if (model.result.location != null)
         {
             location[0] = model.result.location.lat;
             location[1] = model.result.location.lng;
         }
     }
     return(location);
 }
        /// <summary>
        /// 地址取坐标
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        public string Test2(string address)
        {
            Geocoding gd = new Geocoding(new GeocodingParam()
            {
                address  = address,
                ak       = "",
                callback = "",
                city     = "",
                output   = "json",
                sn       = ""
            }
                                         );
            GeocoderResultModel gdresult = gd.GetGeocoderResult();

            // _Address = GetAddress(gdresult);
            double[] ss = GetLocation(gdresult); float f1 = 1.123456789f; float f2 = 110.123456789f;

            return(ss[0] + "," + ss[1] + "<br/><br/>" + f1 + ";;" + f2 + "<br/>" + Serializer.ToJson(gdresult));;
        }
        public ActionResult AddScene(ScenesNewModel model)
        {
            string _enterpriseID = BCSession.User.EnterpriseID;
            int?   _departmentID = BCSession.User.DepartmentID;
            string _userID       = BCSession.User.UserID;
            var    result        = new StandardJsonResult <bool>();

            result.Try(() =>
            {
                if (!ModelState.IsValid)
                {
                    throw new KnownException(ModelState.GetFirstError());
                }
                if (model.EndDate < model.BeginDate)
                {
                    throw new KnownException("结束时间需要大于开始时间");
                }
                var dto = (ScenesDto)model;
                if (dto.Address == null || dto.Address.Equals(""))
                {
                    dto.LatitudeAndLongitude = "|";
                }
                else
                {
                    dto.Address  = model.Address;
                    Geocoding gd = new Geocoding(new GeocodingParam()
                    {
                        address  = dto.Address,
                        ak       = "",
                        callback = "",
                        city     = "",
                        output   = "json",
                        sn       = ""
                    });
                    GeocoderResultModel gdresult = new GeocoderResultModel();
                    try
                    {
                        gdresult = gd.GetGeocoderResult();
                    }

                    finally
                    {
                        double[] ss = GetLocation(gdresult);
                        dto.LatitudeAndLongitude = ss[0] + "|" + ss[1];
                    }
                }
                dto.EnterpriseID = _enterpriseID;
                dto.RegistDate   = DateTime.Now;
                if (model.RoleWorkers == null)
                {
                    dto.Wokers = new List <GroupedUser>();
                }

                else
                {
                    List <GroupedUser> list = new List <GroupedUser>();
                    foreach (var u in model.RoleWorkers)
                    {
                        list.Add(u);
                    }
                    dto.Wokers = list;
                }
                if (dto.ParentSceneID == null || dto.ParentSceneID.Equals(""))
                {
                    dto.ParentSceneID = "-1";
                }
                result.Value = _sceneService.AddScene(dto) != null;
            });

            return(result);
        }