Exemplo n.º 1
0
        /// <summary>
        /// 加载城市信息
        /// </summary>
        /// <returns></returns>
        public int InsertCity()
        {
            List <BCJ_CITY> citys = _book.GetCity();

            JavaScriptSerializer js = new JavaScriptSerializer();

            foreach (var city in citys)
            {
                Thread.Sleep(1000);
                string json = NetHelper.HttpRequest("http://apis.map.qq.com/ws/geocoder/v1/?key=MYVBZ-AO3R3-KVS3G-3OBPF-VNHE5-7VF7M&address=" +
                                                    city.CITY_NAME + "", "",
                                                    "GET", 2000, Encoding.UTF8, "application/json");
                TenAPI api = null;
                if (!json.Contains("查询无结果"))
                {
                    api = js.Deserialize <TenAPI>(json);

                    if (api.status != 0)
                    {
                        api = null;
                    }
                }
                else
                {
                }

                _book.Update(new BCJ_CITY()
                {
                    ID        = city.ID,
                    CITY_CODE = city.CITY_CODE,
                    CITY_NAME = city.CITY_NAME,
                    LATITUDE  = api == null ? "无" : api.result.location.lat,
                    LONGITUDE = api == null ? "无" : api.result.location.lng
                });
            }

            return(1);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 得到城市列表
 /// </summary>
 /// <returns></returns>
 public List <BCJ_CITY> GetCity()
 {
     return(_bcjstor.GetCity());
 }