Azavea.Open.Geocoding.Google.GoogleGeocoder.XMLCandidate2GeocodeCandidate C# (CSharp) Method

XMLCandidate2GeocodeCandidate() private static method

private static XMLCandidate2GeocodeCandidate ( XmlNode XMLCandidate ) : GeocodeCandidate
XMLCandidate System.Xml.XmlNode
return GeocodeCandidate
        private static GeocodeCandidate XMLCandidate2GeocodeCandidate(XmlNode XMLCandidate)
        {
            var candidate = new GeocodeCandidate
                {
                    RawData = XMLCandidate.InnerXml,
                    MatchType = ChildNodeText(XMLCandidate, "type"),
                    StandardizedAddress = ChildNodeText(XMLCandidate, "formatted_address")
                };
            switch (candidate.MatchType)
            {
                case "street_address":
                case "premise":
                case "intersection":
                case "route":
                    candidate.Address = candidate.StandardizedAddress.Split(',')[0];
                    break;
                case "point_of_interest":
                    // Points of interest look like this
                    //   Union Station, 1 Main Street, Burlington, VT 05401, USA
                    // We want the second CSV value
                    candidate.Address = candidate.StandardizedAddress.Split(',')[1];
                    break;
                default:
                    candidate.Address = "";
                    break;
            }
            var locationNode = XMLCandidate.SelectSingleNode("//location");
            if (locationNode != null)
            {
                candidate.Longitude = Convert.ToDouble(ChildNodeText(locationNode, "lng"));
                candidate.Latitude = Convert.ToDouble(ChildNodeText(locationNode, "lat"));
            }
            var componentNodes = XMLCandidate.SelectNodes("//address_component");
            if (componentNodes != null)
            {
                foreach (XmlNode componentNode in componentNodes)
                {
                    var componentType = ChildNodeText(componentNode, "type");
                    var value = ChildNodeText(componentNode, "long_name");
                    switch (componentType)
                    {
                        case "street_address": // indicates a precise street address.
                            break;
                        case "route": // indicates a named route (such as "US 101").
                            break;
                        case "intersection": // indicates a major intersection, usually of two major roads.
                            break;
                        case "street_number": // indicates a major intersection, usually of two major roads.
                            break;
                        case "country": // indicates the national political entity, and is typically the highest order type returned by the Geocoder.
                            candidate.Country = value;
                            break;
                        case "administrative_area_level_1": // indicates a first-order civil entity below the country level. Within the United States, these administrative levels are states. Not all nations exhibit these administrative levels.
                            candidate.State = value;
                            break;
                        case "administrative_area_level_2": // indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties. Not all nations exhibit these administrative levels.
                            break;
                        case "administrative_area_level_3": // indicates a third-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.
                            break;
                        case "colloquial_area": // indicates a commonly-used alternative name for the entity.
                            break;
                        case "locality": // indicates an incorporated city or town political entity.
                            candidate.City = value;
                            break;
                        case "sublocality": // indicates a first-order civil entity below a locality. For some locations may receive one of the additional types: sublocality_level_1 through to sublocality_level_5. Each sublocality level is a civil entity. Larger numbers indicate a smaller geographic area.
                            break;
                        case "neighborhood": // indicates a named neighborhood
                            break;
                        case "premise": // indicates a named location, usually a building or collection of buildings with a common name
                            break;
                        case "subpremise": // indicates a first-order entity below a named location, usually a singular building within a collection of buildings with a common name
                            break;
                        case "postal_code": // indicates a postal code as used to address postal mail within the country.
                            candidate.PostalCode = value;
                            break;
                        case "natural_feature": // indicates a prominent natural feature.
                            break;
                        case "airport": // indicates an airport.
                            break;
                        case "park": // indicates a named park.
                            break;
                        case "point_of_interest": // indicates a named point of interest. Typically, these "POI"s are prominent local entities that don't easily fit in another category such as "Empire State Building" or "Statue of Liberty."
                            break;
                    }
                }
            }

            candidate.MatchScore = ScoreCandidate(XMLCandidate);

            return candidate;
        }