Esempio n. 1
0
        /// <summary>
        /// Renvoi une image de la carte en fonction d'une adresse postale
        /// </summary>
        /// <param name="geo">Parammêtres de l'adresse postale</param>
        /// <returns>Image ou nul</returns>
        public static Image physicalAddressToMapImage(GeoStructure geo)
        {
            GeoStructure gs = geo;

            physicalAddressToGeoCodes(ref gs);
            return(geoCodesToMapImage(gs.latitude, gs.longitude));
        }
Esempio n. 2
0
 /// <summary>
 /// Retrouve les coordonnées géographiques en fonction d'une adresse postale
 /// </summary>
 /// <param name="geo">Parammêtres de l'adresse postale</param>
 public static void physicalAddressToGeoCodes(ref GeoStructure geo)
 {
     if (Properties.Settings.Default.Properties["YAK"] != null && Properties.Settings.Default.Properties["YGCU"] != null)
     {
         string yak  = Properties.Settings.Default.YAK.Trim();
         string ygcu = Properties.Settings.Default.YGCU.Trim();
         if (yak != string.Empty && ygcu != string.Empty)
         {
             string url = ygcu + "?appid=" + yak + "&output=xml";
             if (geo.location != null)
             {
                 url += "&address=" + HttpUtility.UrlEncode(geo.location.Trim(), Encoding.UTF8);
             }
             else
             {
                 if (geo.street != null)
                 {
                     url += "&street=" + HttpUtility.UrlEncode(geo.street.Trim(), Encoding.UTF8);
                 }
                 if (geo.city != null)
                 {
                     url += "&city=" + HttpUtility.UrlEncode(geo.city.Trim(), Encoding.UTF8);
                 }
                 if (geo.zipcode != null)
                 {
                     url += "&zip=" + HttpUtility.UrlEncode(geo.zipcode.Trim(), Encoding.UTF8);
                 }
             }
             url += "&state=" + ((geo.country != null) ? HttpUtility.UrlEncode(geo.country.Trim(), Encoding.UTF8) : string.Empty);
             try
             {
                 WebClient wc       = new WebClient();
                 string    response = wc.DownloadString(url);
                 wc.Dispose();
                 XmlDocument xDoc = new XmlDocument();
                 xDoc.LoadXml(response);
                 if (xDoc.DocumentElement != null && xDoc.DocumentElement["Result"] != null)
                 {
                     XmlElement result = xDoc.DocumentElement["Result"];
                     if (result["Latitude"] != null)
                     {
                         geo.latitude = Convert.ToDouble(result["Latitude"].InnerText, System.Globalization.CultureInfo.InvariantCulture);
                     }
                     if (result["Longitude"] != null)
                     {
                         geo.longitude = Convert.ToDouble(result["Longitude"].InnerText, System.Globalization.CultureInfo.InvariantCulture);
                     }
                 }
             }
             catch (Exception ex) { Console.WriteLine(ex); }
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Renvoi une image de la carte en fonction d'une adresse postale
 /// </summary>
 /// <param name="geo">Parammêtres de l'adresse postale</param>
 /// <returns>Image ou nul</returns>
 public static Image physicalAddressToMapImage(GeoStructure geo)
 {
     GeoStructure gs = geo;
     physicalAddressToGeoCodes(ref gs);
     return geoCodesToMapImage(gs.latitude, gs.longitude);
 }
Esempio n. 4
0
 /// <summary>
 /// Retrouve les coordonnées géographiques en fonction d'une adresse postale
 /// </summary>
 /// <param name="geo">Parammêtres de l'adresse postale</param>
 public static void physicalAddressToGeoCodes(ref GeoStructure geo)
 {
     if (Properties.Settings.Default.Properties["YAK"] != null && Properties.Settings.Default.Properties["YGCU"] != null)
     {
         string yak = Properties.Settings.Default.YAK.Trim();
         string ygcu = Properties.Settings.Default.YGCU.Trim();
         if (yak != string.Empty && ygcu != string.Empty)
         {
             string url = ygcu + "?appid=" + yak + "&output=xml";
             if (geo.location != null)
             {
                 url += "&address=" + HttpUtility.UrlEncode(geo.location.Trim(), Encoding.UTF8);
             }
             else
             {
                 if (geo.street != null) { url += "&street=" + HttpUtility.UrlEncode(geo.street.Trim(), Encoding.UTF8); }
                 if (geo.city != null) { url += "&city=" + HttpUtility.UrlEncode(geo.city.Trim(), Encoding.UTF8); }
                 if (geo.zipcode != null) { url += "&zip=" + HttpUtility.UrlEncode(geo.zipcode.Trim(), Encoding.UTF8); }
             }
             url += "&state=" + ((geo.country != null) ? HttpUtility.UrlEncode(geo.country.Trim(), Encoding.UTF8) : string.Empty);
             try
             {
                 WebClient wc = new WebClient();
                 string response = wc.DownloadString(url);
                 wc.Dispose();
                 XmlDocument xDoc = new XmlDocument();
                 xDoc.LoadXml(response);
                 if (xDoc.DocumentElement != null && xDoc.DocumentElement["Result"] != null)
                 {
                     XmlElement result = xDoc.DocumentElement["Result"];
                     if (result["Latitude"] != null) { geo.latitude = Convert.ToDouble(result["Latitude"].InnerText, System.Globalization.CultureInfo.InvariantCulture); }
                     if (result["Longitude"] != null) { geo.longitude = Convert.ToDouble(result["Longitude"].InnerText, System.Globalization.CultureInfo.InvariantCulture); }
                 }
             }
             catch (Exception ex) { Console.WriteLine(ex); }
         }
     }
 }