Example #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));
            }
        }
	    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("components");

	        this.type = type;
	        this.components = components;
	        this.isPartialMatch = isPartialMatch;
	        this.viewport = viewport;
	        this.locationType = locationType;
	    }
Example #3
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("components");
            }

            this.type           = type;
            this.components     = components;
            this.isPartialMatch = isPartialMatch;
            this.viewport       = viewport;
            this.locationType   = locationType;
        }
 public void CanParseLocationTypes(string address, GoogleLocationType type)
 {
     GoogleAddress[] addresses = geocoder.Geocode(address).ToArray();
     Assert.Equal(type, addresses[0].LocationType);
 }
		public void CanParseLocationTypes(string address, GoogleLocationType type)
		{
			GoogleAddress[] addresses = geocoder.Geocode(address).ToArray();
			Assert.Equal(type, addresses[0].LocationType);
		}
Example #6
0
 public async Task CanParseLocationTypes(string address, GoogleLocationType type)
 {
     GoogleAddress[] addresses = (await geocoder.GeocodeAsync(address)).ToArray();
     Assert.Equal(type, addresses[0].LocationType);
 }