Esempio n. 1
0
        /// <summary>
        /// Метод получения основного (точного) геокода для адреса
        /// </summary>
        /// <param name="d">Коллекция всех геокодов для адреса</param>
        /// <returns>Возвращает точный геокод (если он есть)</returns>
        private GeoCod GetMainGeoCod(List <GeoCod> d)
        {
            GeoCod data = null;

            if (d != null && d.Any())
            {
                if (d.Count == 1)
                {
                    data = d.FirstOrDefault();
                }
                else
                {
                    var l = d.Where(x => x.Precision == PrecisionType.Exact);
                    if (l.Count() == 1)
                    {
                        data = l.FirstOrDefault();
                    }
                }
            }

            return(data);
        }
Esempio n. 2
0
        /// <summary>
        /// Метод получения коллекции геокодов для адреса
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        private List <GeoCod> GetListGeoCod(IEnumerable <GeoCodingService.GeoCod> d)
        {
            List <GeoCod> list = null;

            if (d != null && d.Any())
            {
                list = new List <GeoCod>(d.Count());

                foreach (var g in d)
                {
                    GeoCod data = new GeoCod()
                    {
                        AddressWeb = g.Text,
                        Latitude   = g.Latitude.Replace(',', '.'),
                        Longitude  = g.Longitude.Replace(',', '.')
                    };

                    if (Enum.TryParse(g.Kind?.ToUpperFistChar(), out KindType kind))
                    {
                        data.Kind = kind;
                    }
                    else if (g.Kind == "place" || g.Kind == "suburb")
                    {
                        data.Kind = KindType.Locality;
                    }
                    else if (g.Kind == "houseNumber")
                    {
                        data.Kind = KindType.House;
                    }
                    else if (g.Kind == "street")
                    {
                        data.Kind = KindType.Street;
                    }

                    if (Enum.TryParse(g.Precision?.ToUpperFistChar(), out PrecisionType precision))
                    {
                        data.Precision = precision;
                    }
                    else if (string.IsNullOrEmpty(g.Precision))
                    {
                        data.Precision = PrecisionType.None;
                    }
                    else if (g.Precision?.ToLower() == "true")
                    {
                        data.Precision = PrecisionType.Exact;
                    }
                    else if (g.Precision == "1.0")
                    {
                        data.Precision = PrecisionType.Exact;
                    }
                    else
                    {
                        if (data.Kind == KindType.Street)
                        {
                            data.Precision = PrecisionType.Street;
                        }
                        else if (data.Kind == KindType.House)
                        {
                            data.Precision = PrecisionType.Near;
                        }
                        else
                        {
                            data.Precision = PrecisionType.Other;
                        }
                    }

                    if (data.Precision == PrecisionType.Exact)
                    {
                        data.Qcode = 1;
                    }
                    else if (data.Precision == PrecisionType.None)
                    {
                        data.Qcode = 0;
                    }
                    else
                    {
                        data.Qcode = 2;
                    }

                    list.Add(data);
                }
            }

            return(list);
        }