Exemple #1
0
        private IEnumerable <GoogleAddress> ParseAddresses(XPathNodeIterator nodes)
        {
            while (nodes.MoveNext())
            {
                XPathNavigator nav = nodes.Current;

                GoogleAddressType type             = EvaluateType((string)nav.Evaluate("string(type)"));
                string            formattedAddress = (string)nav.Evaluate("string(formatted_address)");

                var components = ParseComponents(nav.Select("address_component")).ToArray();

                double   latitude    = (double)nav.Evaluate("number(geometry/location/lat)");
                double   longitude   = (double)nav.Evaluate("number(geometry/location/lng)");
                Location coordinates = new Location(latitude, longitude);

                double   neLatitude    = (double)nav.Evaluate("number(geometry/viewport/northeast/lat)");
                double   neLongitude   = (double)nav.Evaluate("number(geometry/viewport/northeast/lng)");
                Location neCoordinates = new Location(neLatitude, neLongitude);

                double   swLatitude    = (double)nav.Evaluate("number(geometry/viewport/southwest/lat)");
                double   swLongitude   = (double)nav.Evaluate("number(geometry/viewport/southwest/lng)");
                Location swCoordinates = new Location(swLatitude, swLongitude);

                var viewport = new GoogleViewport {
                    Northeast = neCoordinates, Southwest = swCoordinates
                };

                GoogleLocationType locationType = EvaluateLocationType((string)nav.Evaluate("string(geometry/location_type)"));

                bool isPartialMatch;
                bool.TryParse((string)nav.Evaluate("string(partial_match)"), out isPartialMatch);

                yield return(new GoogleAddress(type, formattedAddress, components, coordinates, viewport, isPartialMatch, locationType));
            }
        }
Exemple #2
0
        public GoogleAddress(GoogleAddressType type, string formattedAddress, GoogleAddressComponent[] components,
                             Location coordinates, GoogleViewport viewport, bool isPartialMatch, GoogleLocationType locationType)
            : base(formattedAddress, coordinates, "Google")
        {
            if (components == null)
            {
                throw new ArgumentNullException(nameof(components));
            }

            this.type           = type;
            this.components     = components;
            this.isPartialMatch = isPartialMatch;
            this.viewport       = viewport;
            this.locationType   = locationType;
        }