コード例 #1
0
        public void ShowAll(object obj)
        {
            List <Point2D> points = obj as List <Point2D>;

            if (points == null)
            {
                return;
            }

            GeoCoderStatusCode status = GeoCoderStatusCode.Unknow;
            List <Placemark>   list   = new List <Placemark>();

            foreach (Point2D pnt in points)
            {
                Placemark place = GeoCoder.GetPlacemark(pnt, out status);
                place.Location = pnt;
                list.Add(place);
            }
            this.listBox1.DataSource = list;
        }
コード例 #2
0
 /// <summary>
 /// Zooms to location
 /// </summary>
 private void listBox1_MouseDoubleClick_1(object sender, MouseEventArgs e)
 {
     #if OCX_VERSION49
     if (listBox1.SelectedItem != null)
     {
         if (listBox1.SelectedItem is Point2D)
         {
             Point2D pnt = listBox1.SelectedItem as Point2D;
             this.UpdateMapPosition(pnt.Lat, pnt.Lng);
         }
         else if (listBox1.SelectedItem is Placemark)
         {
             Placemark place = listBox1.SelectedItem as Placemark;
             if (place.Location != null)
             {
                 this.UpdateMapPosition(place.Location.Lat, place.Location.Lng);
             }
         }
     }
     #endif
 }
コード例 #3
0
        /// <summary>
        /// Gets list of names by sending HTTP request with location
        /// </summary>
        private static GeoCoderStatusCode GetPlacemarkFromReverseGeocoderUrl(string url, out List <Placemark> placemarkList)
        {
            GeoCoderStatusCode status = GeoCoderStatusCode.Unknow;

            placemarkList = null;

            try
            {
                string urlEnd = url.Substring(url.IndexOf("geo?hl="));

                string reverse = reverse = GetContentUsingHttp(url);

                if (!string.IsNullOrEmpty(reverse))
                {
                    if (reverse.StartsWith("200"))
                    {
                        string acc = reverse.Substring(0, reverse.IndexOf('\"'));
                        var    ret = new Placemark(reverse.Substring(reverse.IndexOf('\"')));
                        ret.Accuracy  = int.Parse(acc.Split(',').GetValue(1) as string);
                        placemarkList = new List <Placemark>();
                        placemarkList.Add(ret);
                        status = GeoCoderStatusCode.G_GEO_SUCCESS;
                    }
                    else if (reverse.StartsWith("<?xml"))
                    {
                        #region -- kml version --
                        //<?xml version="1.0" encoding="UTF-8" ?>
                        //<kml xmlns="http://earth.server.com/kml/2.0">
                        // <Response>
                        //  <name>55.023322,24.668408</name>
                        //  <Status>
                        //    <code>200</code>
                        //    <request>geocode</request>
                        //  </Status>

                        //  <Placemark id="p1">
                        //    <address>4313, Širvintos 19023, Lithuania</address>
                        //    <AddressDetails Accuracy="6" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>LT</CountryNameCode><CountryName>Lithuania</CountryName><SubAdministrativeArea><SubAdministrativeAreaName>Vilnius Region</SubAdministrativeAreaName><Locality><LocalityName>Širvintos</LocalityName><Thoroughfare><ThoroughfareName>4313</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>19023</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></Country></AddressDetails>
                        //    <ExtendedData>
                        //      <LatLonBox north="55.0270661" south="55.0207709" east="24.6711965" west="24.6573382" />
                        //    </ExtendedData>
                        //    <Point><coordinates>24.6642677,55.0239187,0</coordinates></Point>
                        //  </Placemark>

                        //  <Placemark id="p2">
                        //    <address>Širvintos 19023, Lithuania</address>
                        //    <AddressDetails Accuracy="5" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>LT</CountryNameCode><CountryName>Lithuania</CountryName><SubAdministrativeArea><SubAdministrativeAreaName>Vilnius Region</SubAdministrativeAreaName><Locality><LocalityName>Širvintos</LocalityName><PostalCode><PostalCodeNumber>19023</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></Country></AddressDetails>
                        //    <ExtendedData>
                        //      <LatLonBox north="55.1109513" south="54.9867479" east="24.7563286" west="24.5854650" />
                        //    </ExtendedData>
                        //    <Point><coordinates>24.6778290,55.0561428,0</coordinates></Point>
                        //  </Placemark>

                        //  <Placemark id="p3">
                        //    <address>Širvintos, Lithuania</address>
                        //    <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>LT</CountryNameCode><CountryName>Lithuania</CountryName><SubAdministrativeArea><SubAdministrativeAreaName>Vilnius Region</SubAdministrativeAreaName><Locality><LocalityName>Širvintos</LocalityName></Locality></SubAdministrativeArea></Country></AddressDetails>
                        //    <ExtendedData>
                        //      <LatLonBox north="55.1597127" south="54.8595715" east="25.2358124" west="24.5536348" />
                        //    </ExtendedData>
                        //    <Point><coordinates>24.9447696,55.0482439,0</coordinates></Point>
                        //  </Placemark>

                        //  <Placemark id="p4">
                        //    <address>Vilnius Region, Lithuania</address>
                        //    <AddressDetails Accuracy="3" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>LT</CountryNameCode><CountryName>Lithuania</CountryName><SubAdministrativeArea><SubAdministrativeAreaName>Vilnius Region</SubAdministrativeAreaName></SubAdministrativeArea></Country></AddressDetails>
                        //    <ExtendedData>
                        //      <LatLonBox north="55.5177330" south="54.1276791" east="26.7590747" west="24.3866334" />
                        //    </ExtendedData>
                        //    <Point><coordinates>25.2182138,54.8086502,0</coordinates></Point>
                        //  </Placemark>

                        //  <Placemark id="p5">
                        //    <address>Lithuania</address>
                        //    <AddressDetails Accuracy="1" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>LT</CountryNameCode><CountryName>Lithuania</CountryName></Country></AddressDetails>
                        //    <ExtendedData>
                        //      <LatLonBox north="56.4503174" south="53.8986720" east="26.8356500" west="20.9310000" />
                        //    </ExtendedData>
                        //    <Point><coordinates>23.8812750,55.1694380,0</coordinates></Point>
                        //  </Placemark>
                        //</Response>
                        //</kml>
                        #endregion

                        #region KML
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(reverse);

                        XmlNamespaceManager nsMgr = new XmlNamespaceManager(doc.NameTable);
                        nsMgr.AddNamespace("sm", string.Format("http://earth.{0}/kml/2.0", Server));
                        nsMgr.AddNamespace("sn", "urn:oasis:names:tc:ciq:xsdschema:xAL:2.0");

                        var codeNode = doc.SelectSingleNode("//sm:Status/sm:code", nsMgr);
                        if (codeNode != null)
                        {
                            status = (GeoCoderStatusCode)int.Parse(codeNode.InnerText);
                            if (status == GeoCoderStatusCode.G_GEO_SUCCESS)
                            {
                                placemarkList = new List <Placemark>();
                                XmlNodeList l = doc.SelectNodes("/sm:kml/sm:Response/sm:Placemark", nsMgr);
                                if (l != null)
                                {
                                    foreach (XmlNode n in l)
                                    {
                                        XmlNode nnd, nnl, nn;
                                        {
                                            nn = n.SelectSingleNode("sm:address", nsMgr);
                                            if (nn != null)
                                            {
                                                var ret = new Placemark(nn.InnerText);

                                                nnd = n.SelectSingleNode("sn:AddressDetails", nsMgr);
                                                if (nnd != null)
                                                {
                                                    nn = nnd.SelectSingleNode("@Accuracy", nsMgr);
                                                    if (nn != null)
                                                    {
                                                        ret.Accuracy = int.Parse(nn.InnerText);
                                                    }

                                                    nn = nnd.SelectSingleNode("sn:Country/sn:CountryNameCode", nsMgr);
                                                    if (nn != null)
                                                    {
                                                        ret.CountryNameCode = nn.InnerText;
                                                    }

                                                    nn = nnd.SelectSingleNode("sn:Country/sn:CountryName", nsMgr);
                                                    if (nn != null)
                                                    {
                                                        ret.CountryName = nn.InnerText;
                                                    }

                                                    nn = nnd.SelectSingleNode("descendant::sn:AdministrativeArea/sn:AdministrativeAreaName", nsMgr);
                                                    if (nn != null)
                                                    {
                                                        ret.AdministrativeAreaName = nn.InnerText;
                                                    }

                                                    nn = nnd.SelectSingleNode("descendant::sn:SubAdministrativeArea/sn:SubAdministrativeAreaName", nsMgr);
                                                    if (nn != null)
                                                    {
                                                        ret.SubAdministrativeAreaName = nn.InnerText;
                                                    }

                                                    // Locality or DependentLocality tag ?
                                                    nnl = nnd.SelectSingleNode("descendant::sn:Locality", nsMgr) ?? nnd.SelectSingleNode("descendant::sn:DependentLocality", nsMgr);
                                                    if (nnl != null)
                                                    {
                                                        nn = nnl.SelectSingleNode(string.Format("sn:{0}Name", nnl.Name), nsMgr);
                                                        if (nn != null)
                                                        {
                                                            ret.LocalityName = nn.InnerText;
                                                        }

                                                        nn = nnl.SelectSingleNode("sn:Thoroughfare/sn:ThoroughfareName", nsMgr);
                                                        if (nn != null)
                                                        {
                                                            ret.ThoroughfareName = nn.InnerText;
                                                        }

                                                        nn = nnl.SelectSingleNode("sn:PostalCode/sn:PostalCodeNumber", nsMgr);
                                                        if (nn != null)
                                                        {
                                                            ret.PostalCodeNumber = nn.InnerText;
                                                        }
                                                    }
                                                }
                                                placemarkList.Add(ret);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                placemarkList = null;
                Debug.WriteLine("GetPlacemarkReverseGeocoderUrl: " + ex.ToString());
            }

            return(status);
        }