Exemplo n.º 1
0
        public bool ReadPOIPage(string keyword, int pageSize, List <POI> list, int pageNum = 0)
        {
            var    url     = string.Format(_apiGetPOI, keyword, LeftBottom.Lat, LeftBottom.Lng, RightTop.Lat, RightTop.Lng, AKProvider.Peek(), pageSize, pageNum);
            string content = null;

            WebClient wc     = new WebClient();
            var       stream = wc.OpenRead(url);

            if (stream != null)
            {
                StreamReader sr = new StreamReader(stream);
                content = sr.ReadToEnd();
                sr.Close();
                stream.Close();
            }
            wc.Dispose();
            if (!string.IsNullOrEmpty(content))
            {
                JsonContent = content;
                JavaScriptSerializer jss = new JavaScriptSerializer();
                jss.MaxJsonLength = Int32.MaxValue;
                var poi = jss.Deserialize <BaiduMapJSON>(content);
                if (poi.Status == 0)
                {
                    if (poi.Results.Count > 0)
                    {
                        list.AddRange(poi.Results);

                        if (pageSize * ++pageNum < poi.Total)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    //AK失效
                    AKProvider.Pop(AKProvider.Peek());
                    ReadPOIPage(keyword, pageSize, list, pageNum);
                    return(ReadPOIPage(keyword, pageSize, list, pageNum));
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public bool VerifyCity()
        {
            var url = string.Format(_apiGetLocationCity, AKProvider.Peek(), Center.Lat, Center.Lng);

            string content = null;

            WebClient wc     = new WebClient();
            var       stream = wc.OpenRead(url);

            if (stream != null)
            {
                StreamReader sr = new StreamReader(stream);
                content = sr.ReadToEnd();
                sr.Close();
                stream.Close();
            }

            if (!string.IsNullOrEmpty(content))
            {
                JsonContent = content;
                JavaScriptSerializer jss = new JavaScriptSerializer();
                jss.MaxJsonLength = Int32.MaxValue;
                var location = jss.Deserialize <LocationInfoDefinition>(content);
                if (location.Status == 0)
                {
                    if (location.Result.AddressComponent.City.Contains(CityName))
                    {
                        District = location.Result.AddressComponent.District;
                        //Debug.WriteLine(url);
                        InCity = true;
                        return(true);
                    }
                }
                else
                {
                    AKProvider.Pop(AKProvider.Peek());
                    return(VerifyCity());
                }
            }
            wc.Dispose();
            return(false);
        }
Exemplo n.º 3
0
        private Location GetCityCenter()
        {
            var url = string.Format(_apiFindCityLocation, AKProvider.Peek(), CityName);

            string content = null;

            WebClient wc     = new WebClient();
            var       stream = wc.OpenRead(url);

            if (stream != null)
            {
                StreamReader sr = new StreamReader(stream);
                content = sr.ReadToEnd();
                sr.Close();
                stream.Close();
            }

            if (!string.IsNullOrEmpty(content))
            {
                JsonContent = content;
                JavaScriptSerializer jss = new JavaScriptSerializer();
                jss.MaxJsonLength = Int32.MaxValue;
                var city = jss.Deserialize <CityLocationDefinition>(content);
                if (city.Result.Level == "城市")
                {
                    var location = city.Result.Location;
                    return(location);
                }
                else
                {
                    throw new ApplicationException("您输入的地名不是城市级别,而是" + city.Result.Level);
                }
            }
            wc.Dispose();
            return(null);
        }