Exemplo n.º 1
0
        public string GetCityCode(AddressComponent address)
        {
            WeatherCodeData data            = JsonConvert.DeserializeObject <WeatherCodeData>(MMY.StickyNote.UI.Properties.Resources.WeatherCode);
            string          tempGetProvince = address.province.Substring(0, 2);
            string          tempGetCity     = address.city.Substring(0, 2);
            string          cityCode        = "0";

            //Console.WriteLine(tempGetProvince);
            foreach (var item_p in data.城市代码)
            {
                //Console.WriteLine(item_p.省);
                string tempLocalProvince = item_p.省.Substring(0, 2);
                if (tempGetProvince == tempLocalProvince)
                {
                    foreach (var item_c in item_p.市)
                    {
                        string tempLocalCity = item_c.市名.Substring(0, 2);
                        if (tempGetCity == tempLocalCity)
                        {
                            cityCode = item_c.编码;
                        }
                    }
                }
            }
            return(cityCode);
        }
Exemplo n.º 2
0
        private void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs <GeoCoordinate> e)
        {
            AddressComponent address = GetGeocoderForPositionByBaidu(e.Position.Location.Latitude, e.Position.Location.Longitude);

            if (address == null)
            {
                return;
            }
            //获取城市编码
            string cityCode = GetCityCode(address);
            //使用委托的方式回传地址信息回去,再执行获取天气信息
            string weatherStr = RequestWeatherWebAnalysisData(cityCode);

            _SetWeatherControl(weatherStr);
        }
Exemplo n.º 3
0
        private AddressComponent GetGeocoderForPositionByBaidu(double latitude, double longitude)
        {
            //Console.WriteLine("Latitude: {0}, Longitude {1}", latitude, longitude);
            //********http://api.map.baidu.com/geocoder?location=24.363,109.402&output=json&key=elxrPCAh6eQyyBwqk62NGpKMxhTh1az1

            string staticAddress = "http://api.map.baidu.com/geocoder?";
            string location      = string.Format("{0},{1}", latitude, longitude);

            string url = string.Format("{0}location={1}&output=json&key={2}", staticAddress, location, _ak);

            try
            {
                string           result  = GenerateUrl.Get(url);
                AddressComponent address = AnalyticalData.AnalyticalData_obj(result);
                return(address);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"获取具体地址失败,请稍后右键任务栏小图标点击刷新!", "提示");
                return(null);
            }
        }