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

                GoogleAddressType type             = EvaluateType((string)nav.Evaluate("string(type)"));
                string            placeId          = (string)nav.Evaluate("string(place_id)");
                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)"));

                Bounds bounds = null;
                if (nav.SelectSingleNode("geometry/bounds") != null)
                {
                    double   neBoundsLatitude    = (double)nav.Evaluate("number(geometry/bounds/northeast/lat)");
                    double   neBoundsLongitude   = (double)nav.Evaluate("number(geometry/bounds/northeast/lng)");
                    Location neBoundsCoordinates = new Location(neBoundsLatitude, neBoundsLongitude);

                    double   swBoundsLatitude    = (double)nav.Evaluate("number(geometry/bounds/southwest/lat)");
                    double   swBoundsLongitude   = (double)nav.Evaluate("number(geometry/bounds/southwest/lng)");
                    Location swBoundsCoordinates = new Location(swBoundsLatitude, swBoundsLongitude);

                    bounds = new Bounds(swBoundsCoordinates, neBoundsCoordinates);
                }

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

                yield return(new GoogleAddress(type, formattedAddress, components, coordinates, viewport, bounds, isPartialMatch, locationType, placeId));
            }
        }
Ejemplo n.º 2
0
        public GoogleAddress(GoogleAddressType type, string formattedAddress, GoogleAddressComponent[] components,
                             Location coordinates, GoogleViewport viewport, Bounds bounds, bool isPartialMatch, GoogleLocationType locationType, string placeId)
            : base(formattedAddress, coordinates, "Google")
        {
            if (components == null)
            {
                throw new ArgumentNullException("components");
            }

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