Inheritance: System.EventArgs
Ejemplo n.º 1
0
 private void OnReverseGeocoded(object sender, GeocodeEventArgs args)
 {
     Log.Info("MapView.OnReverseGeocoded", "Address:{0}", args.Address);
     MethodInvoker methodInvoker = delegate
     {
         textBoxLocationName.Value = args.ToString();
         WaitCursor.Hide();
     };
     if (InvokeRequired)
     {
         BeginInvoke(methodInvoker);
     }
     else
     {
         methodInvoker.Invoke();
     }
 }
        private void ReverseGeocodeInternal()
        {
            try
            {
                StringBuilder url = new StringBuilder("http://maps.google.com/maps/geo?oe=utf-8");
                url.AppendFormat("&output={0}", "xml");
                url.AppendFormat("&key={0}", MapApiKey);
                url.AppendFormat("&ll={0},{1}", Latitude, Longitude);

                Log.Info("GoogleGeocodeService.ReverseGeocodeInternal()", "URL: {0}", url);

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url.ToString());
                request.KeepAlive = false;
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    using (Stream dataStream = response.GetResponseStream())
                    {
                        XmlDocument document = new XmlDocument();
                        document.Load(dataStream);

                        GeocodeEventArgs geocodeEventArgs = new GeocodeEventArgs
                        {
                            Address = GetElementByTagName(document, "address"),
                            Administrative = GetElementByTagName(document, "AdministrativeAreaName"),
                            SubAdministrative = GetElementByTagName(document, "SubAdministrativeAreaName"),
                            Locality = GetElementByTagName(document, "LocalityName"),
                            Thoroughfare = GetElementByTagName(document, "ThoroughfareName"),
                            PostalCode = GetElementByTagName(document, "PostalCodeNumber"),
                            Country = GetElementByTagName(document, "CountryNameCode")
                        };

                        if (ReverseGeocoded != null)
                        {
                            ReverseGeocoded(this, geocodeEventArgs);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("GoogleGeocodeService.ReverseGeocodeInternal", "Exception: {0}", ex.Message);
            }
        }