コード例 #1
0
        public bool EqualsMd5Code(LocationAddress locationAddress)
        {
            if (locationAddress == null)
            {
                return(false);
            }

            return(string.Equals(GetMd5Code(), locationAddress.GetMd5Code()));
        }
コード例 #2
0
        public bool EqualsCoordinates(LocationAddress locationAddress)
        {
            if (locationAddress == null)
            {
                return(false);
            }

            // ReSharper disable once CompareOfFloatsByEqualityOperator
            return(HasCoordinates && Locality == locationAddress.Locality && Longitude == locationAddress.Longitude);
        }
コード例 #3
0
        public static LocationAddress Parse(string address)
        {
            if (string.IsNullOrEmpty(address))
            {
                return(null);
            }

            var result         = new LocationAddress();
            var formatProvider = GetFormatProvider();
            var parse          = address.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            foreach (var p in parse)
            {
                var value = p.Trim();
                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }

                if (!result.Latitude.HasValue && value.Length > 1 && value.StartsWith("("))
                {
                    if (double.TryParse(value.Substring(1), NumberStyles.Number, formatProvider, out double latitude))
                    {
                        result.Latitude = latitude;
                        continue;
                    }
                }
                if (!result.Longitude.HasValue && value.Length > 1 && value.EndsWith(")"))
                {
                    if (double.TryParse(value.Substring(0, value.Length - 1), NumberStyles.Number, formatProvider,
                                        out double longitude))
                    {
                        result.Longitude = longitude;
                        continue;
                    }
                }
                if (string.IsNullOrEmpty(result.Locality))
                {
                    result.Locality = value;
                    continue;
                }
                if (string.IsNullOrEmpty(result.CountryCode))
                {
                    result.CountryCode = value.ToUpper();
                }
            }

            return(result);
        }