Пример #1
0
        private static IEnumerable <Address> ParseAddresses(
            [NotNull] XPathNodeIterator nodes)
        {
            nodes.IsNotNull(nameof(nodes));

            while (nodes.MoveNext())
            {
                var nav = nodes.Current;

                var type = evaluateType(
                    nav.Extract <string>(
                        "string(type)"));

                var placeId = nav.Extract <string>(
                    "string(place_id)");

                var formattedAddress = nav.Extract <string>(
                    "string(formatted_address)");

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


                var latitude = nav.Extract <double>(
                    "number(geometry/location/lat)");

                var longitude = nav.Extract <double>(
                    "number(geometry/location/lng)");

                var coordinates = new Location(
                    latitude,
                    longitude);


                var northEastLatitude = nav.Extract <double>(
                    "number(geometry/viewport/northeast/lat)");

                var northEastLongitude = nav.Extract <double>(
                    "number(geometry/viewport/northeast/lng)");

                var northEastCoordinates = new Location(
                    northEastLatitude,
                    northEastLongitude);


                var southWestLatitude = nav.Extract <double>(
                    "number(geometry/viewport/southwest/lat)");

                var southWestLongitude = nav.Extract <double>(
                    "number(geometry/viewport/southwest/lng)");

                var southWestCoordinates = new Location(
                    southWestLatitude,
                    southWestLongitude);


                var viewport = new Viewport
                {
                    Northeast = northEastCoordinates,
                    Southwest = southWestCoordinates
                };

                var locationType = evaluateLocationType(
                    nav.Extract <string>("string(geometry/location_type)"));

                Bounds bounds = null;
                if (nav.SelectSingleNode("geometry/bounds") != null)
                {
                    var northEastBoundsLatitude = nav.Extract <double>(
                        "number(geometry/bounds/northeast/lat)");

                    var northEastBoundsLongitude = nav.Extract <double>(
                        "number(geometry/bounds/northeast/lng)");

                    var northEastBoundsCoordinates = new Location(
                        northEastBoundsLatitude,
                        northEastBoundsLongitude);


                    var southWestBoundsLatitude = nav.Extract <double>(
                        "number(geometry/bounds/southwest/lat)");

                    var southWestBoundsLongitude = nav.Extract <double>(
                        "number(geometry/bounds/southwest/lng)");

                    var southWestBoundsCoordinates = new Location(
                        southWestBoundsLatitude,
                        southWestBoundsLongitude);

                    bounds = new Bounds(
                        southWestBoundsCoordinates,
                        northEastBoundsCoordinates);
                }

                bool isPartialMatch;

                bool.TryParse(
                    nav.Extract <string>("string(partial_match)"),
                    out isPartialMatch);

                yield return(new Address(
                                 type,
                                 formattedAddress,
                                 components,
                                 coordinates,
                                 viewport,
                                 bounds,
                                 isPartialMatch,
                                 locationType,
                                 placeId));
            }
        }