Beispiel #1
0
        public void GetAddressFromGeoCoordinate(GeoCoordinate location)
        {
            this.Location = location;

            DownloadGeoCodeResultCompletedEventArgs completedEvent = new DownloadGeoCodeResultCompletedEventArgs();


            if (location.IsUnknown == true)
            {
                completedEvent.Status = "LocationUnknown";
                OnDownloadStringCompleted(completedEvent);//イベントを発行する。
                return;
            }

            if (DeviceNetworkInformation.IsNetworkAvailable == false)
            {
                completedEvent.Status = "NoNetWork";
                OnDownloadStringCompleted(completedEvent);//イベントを発行する。
                return;
            }

            CultureInfo cc = Thread.CurrentThread.CurrentCulture;

            // URI で識別されるリソースとのデータの送受信用の共通クラス
            WebClient downloadClient = new WebClient();

            // URL
            Uri requestURL = new Uri(string.Format("http://maps.googleapis.com/maps/api/geocode/xml?latlng={0},{1}&language={2}&sensor=false", location.Latitude, location.Longitude, cc.ToString()));

            // ジオコーティング

            //WebClientTimeout.Start();
            downloadClient.DownloadStringCompleted += downloadClient_DownloadStringCompleted;
            downloadClient.DownloadStringAsync(requestURL);
        }
Beispiel #2
0
 protected virtual void OnDownloadStringCompleted(DownloadGeoCodeResultCompletedEventArgs e)//このメソッドでイベント発行。
 {
     if (DownloadGeoCodeResultCompleted != null)
     {
         DownloadGeoCodeResultCompleted(this, e);
     }
 }
Beispiel #3
0
        public void GetGeoCoordintateFromAddress(string address)
        {
            DownloadGeoCodeResultCompletedEventArgs completedEvent = new DownloadGeoCodeResultCompletedEventArgs();

            if (DeviceNetworkInformation.IsNetworkAvailable == false)
            {
                completedEvent.Status = "NoNetWork";
                OnDownloadStringCompleted(completedEvent);//イベントを発行する。
                return;
            }

            CultureInfo cc = Thread.CurrentThread.CurrentCulture;
            // URI で識別されるリソースとのデータの送受信用の共通クラス
            WebClient downloadClient = new WebClient();
            string    encodedAddress = HttpUtility.UrlEncode(address);

            System.Diagnostics.Debug.WriteLine(encodedAddress);
            // URL
            Uri requestURL = new Uri(string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&language={1}&sensor=false", address, cc.ToString()));

            /*
             * # 住所から緯度・経度を取得
             *
             *   https://maps.google.co.jp/maps?hl=ja&q=%E6%9C%AD%E5%B9%8C&lr=lang_ja&ie=UTF-8&ei=1D9UUruaEOKFiQewxICgDg&ved=0CAoQ_AUoAg
             */
            // ジオコーティング
            //string encodedRequestURL = HttpUtility.UrlEncode(string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&language={1}&sensor=false",address, cc.ToString()));
            System.Diagnostics.Debug.WriteLine(requestURL);
            downloadClient.DownloadStringCompleted += downloadClient_DownloadStringCompleted;
            downloadClient.DownloadStringAsync(requestURL);
        }
Beispiel #4
0
        void WebClientTimeout_Tick(object sender, EventArgs e)
        {
            DownloadGeoCodeResultCompletedEventArgs completedEvent = new DownloadGeoCodeResultCompletedEventArgs();

            completedEvent.Status   = "TimeOut";
            completedEvent.Location = this.Location;

            OnDownloadStringCompleted(completedEvent);//イベントを発行する。

            //WebClientTimeout.Stop();
        }
Beispiel #5
0
        void downloadClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            //WebClientTimeout.Stop();

            DownloadGeoCodeResultCompletedEventArgs completedEvent = new DownloadGeoCodeResultCompletedEventArgs();

            if (e.Error != null)
            {
                completedEvent.Status   = "Error";
                completedEvent.Location = this.Location;
            }
            else
            {
                completedEvent.Status   = "Completed";
                completedEvent.Result   = e.Result;
                completedEvent.Location = this.Location;
            }

            OnDownloadStringCompleted(completedEvent);//イベントを発行する。
        }
        void geoCode_DownloadGeoCodeResultCompleted(object sender, DownloadGeoCodeResultCompletedEventArgs e)
        {
            if (e.Status != "Completed")
            {
                TextBox_Address.Text = "";
                return;
            }

            try
            {
                var xmlDoc    = XElement.Parse(e.Result);
                var ns        = xmlDoc.Name.Namespace;
                var addresses = from address in xmlDoc.Descendants(ns + "formatted_address")
                                select address;

                if (addresses.Count() == 0)
                {
                    TextBox_Address.Text = "";
                }
                else
                {
                    var firstElement = addresses.First();
                    //string address = (string)firstElement.Element(ns + "address").Value;

                    string address = firstElement.Value;
                    TextBox_Address.Text = address;


                    if (newItemFlag == false)
                    {
                        UIToPushPinView();
                        //DB.SaveInfoToIsoStrage(PushPinView);
                    }
                }
            }
            catch
            {
                TextBox_Address.Text = "";
            }
        }
        //住所から経緯度を取得
        private void geoCode_DownloadReverseGeoCodeResultCompleted(object sender, DownloadGeoCodeResultCompletedEventArgs e)
        {
            if (e.Status != "Completed")
            {
                //return;
            }
            else
            {
                try
                {
                    var xmlDoc = XElement.Parse(e.Result);
                    var ns     = xmlDoc.Name.Namespace;
                    var places = from place in xmlDoc.Descendants(ns + "Placemark")
                                 select place;

                    if (places.Count() == 0)
                    {
                        TextBox_Latitude.Text  = "";
                        TextBox_Longitude.Text = "";
                    }
                    else
                    {
                        var      firstElement  = places.First();
                        string[] geocoordinate = ((string)firstElement.Element(ns + "Point").Element(ns + "coordinates").Value).Split(',');

                        TextBox_Latitude.Text  = geocoordinate[1];
                        TextBox_Longitude.Text = geocoordinate[0];
                    }
                }
                catch
                {
                    TextBox_Latitude.Text  = "";
                    TextBox_Longitude.Text = "";
                }
            }

            //経緯度を取得できなかった場合に、現状を初期状態として記録
            //StrBefore = TextBox_Title.Text + TextBox_Note.Text + TextBox_Latitude.Text + TextBox_Longitude.Text + TextBox_Address.Text;
        }
        private void geoCode_DownloadReverseGeoCodeResultCompleted(object sender, DownloadGeoCodeResultCompletedEventArgs e)
        {
            if (e.Status != "Completed")
            {
                return;
            }

            var xmlDoc = XElement.Parse(e.Result);
            var ns     = xmlDoc.Name.Namespace;

            var locations = from location in xmlDoc.Descendants(ns + "location")
                            select location;

            if (locations.Count() == 0)
            {
                return;
            }
            var firstElement = locations.First();

            //string[] geocoordinate = ((string)firstElement.Element(ns + "Point").Element(ns + "coordinates").Value).Split(',');
            string[] geocoordinate = new string[] { firstElement.Element(ns + "lat").Value, firstElement.Element(ns + "lng").Value };



            var searchLocation = new GeoCoordinate(Convert.ToDouble(geocoordinate[0]), Convert.ToDouble(geocoordinate[1]));

            PushPinView.ClearSelected();

            //候補地ピンの座標を設定
            candidatePin.Location = searchLocation;

            MyMap.SetView(candidatePin.Location, MyMap.ZoomLevel);

            if (MyMap.Children.Contains(candidatePin) == false)
            {
                MyMap.Children.Add(candidatePin);
            }
        }
        void geoCode_DownloadGeoCodeResultCompleted(object sender, DownloadGeoCodeResultCompletedEventArgs e)
        {
            /*
             * PushPinModel pin = new PushPinModel();
             * pin.Location = e.Location; //new GeoCoordinate(holdLocation.Latitude, holdLocation.Longitude),
             * pin.Name = "New Place";
             * pin.Color = new SolidColorBrush(Utility.GetColorFromHexString(PushPinView.DefaultColor_Hex));
             * pin.Note = "";
             * pin.IsEnabled = true;
             * pin.Selected = false;
             * pin.Target = false;
             * pin.Visibility = System.Windows.Visibility.Visible;
             * pin.CreateDate = DateTime.Now;
             */

            PushPinModel pin;

            pin = PushPinView.GetPinByLocation(e.Location);
            if (pin == null)
            {
                return;
            }


            if (e.Status != "Completed")
            {
                pin.Address = "";
            }
            else if (e.Status == "Completed")
            {
                try
                {
                    var xmlDoc = XElement.Parse(e.Result);
                    var ns     = xmlDoc.Name.Namespace;
                    var places = from place in xmlDoc.Descendants(ns + "Placemark")
                                 select place;

                    if (places.Count() == 0)
                    {
                        pin.Address = "";
                    }
                    else
                    {
                        var    firstElement = places.First();
                        string address      = (string)firstElement.Element(ns + "address").Value;

                        pin.Address = address;
                    }
                }
                catch
                {
                    //notsupportedexceptionだったかな?ログイン画面に飛ばされるWifiに接続した状態だと、htmlを取得してしまうのでxmlとして解析できない。
                    pin.Address = "";
                }
            }
            else if (e.Status == "TimeOut")
            {
                pin.Address = "";
            }

            /*
             * pin.PropertyChanged += Pin_PropertyChanged;
             *
             * PushPinView.PushPins.Add(pin);
             * DB.SaveInfoToIsoStrage(PushPinView);
             *
             * var vc = VibrateController.Default;
             * vc.Start(TimeSpan.FromMilliseconds(50));
             */
        }