示例#1
0
        public static LanAndLon GetLatAndLonByWord(string Word)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + Word);

            request.Method      = "GET";
            request.ContentType = "text/html;charset=UTF-8";
            HttpWebResponse response         = (HttpWebResponse)request.GetResponse();
            Stream          myResponseStream = response.GetResponseStream();
            StreamReader    myStreamReader   = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string          retString        = myStreamReader.ReadToEnd();

            myStreamReader.Close();
            myResponseStream.Close();
            JObject jo       = (JObject)JsonConvert.DeserializeObject(retString);
            JToken  geocodes = jo["geocodes"];

            //if (jopos.LongCount() == 0)
            //{
            //    string suggestion = jo["suggestion"]["cities"][0]["name"].ToString();
            //    return GetLantiAndLonti(suggestion);
            //}
            try
            {
                String[]  laandlon = geocodes[0]["location"].ToString().Split(',');
                string    name     = geocodes[0]["formatted_address"].ToString();
                int       level    = levellist.IndexOf(geocodes[0]["level"].ToString());
                LanAndLon ll       = new LanAndLon(Convert.ToDouble(laandlon[1]), Convert.ToDouble(laandlon[0]), name, level);
                return(ll);
            }
            catch (Exception)
            {
                return(new LanAndLon());
            }
        }
示例#2
0
        public void GetLantiAndLontiTest()
        {
            LanAndLon res = GetLanAndLon.GetLatAndLonByWord("北京");
            LanAndLon ll  = new LanAndLon(39.904030, 116.407526, "北京市", 1);

            Assert.AreEqual(res.lat, ll.lat);
            Assert.AreEqual(res.lon, ll.lon);
            Assert.AreEqual(res.strPlace, ll.strPlace);
        }
示例#3
0
        public void GetLantiAndLonTest()
        {
            string    title = "新疆克孜勒苏州乌恰县发生3.2级地震 震源深度8千米";
            var       res   = GetLanAndLon.GetLatAndLonByTitle(title);
            LanAndLon ll    = new LanAndLon(39.719310, 75.259228, "新疆维吾尔自治区克孜勒苏柯尔克孜自治州乌恰县", 3);

            Assert.AreEqual(res.lat, ll.lat);
            Assert.AreEqual(res.lon, ll.lon);
            Assert.AreEqual(res.strPlace, ll.strPlace);
        }
示例#4
0
文件: Crawler.cs 项目: yanwen0614/PM
        protected LanAndLon GetLocation(string Title)
        {
            LanAndLon ll = null;

            ll = GetLanAndLon.GetLatAndLonByTitle(Title);
            String sqlKeyTitleTable = "insert into LocationPOI (Place,Lontitude,Latitude) " +
                                      " values ('" + ll.strPlace + "'," + ll.lon + "," + ll.lat + ")";

            DB.Update(sqlKeyTitleTable);
            return(ll);
        }