Exemplo 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            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
                };

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

                yield return(new GoogleAddress(type, formattedAddress, components, coordinates, viewport, isPartialMatch));
            }
        }
        public async Task CanParseAddressTypes(string address, GoogleAddressType type)
        {
            var result = await geoCoder.GeocodeAsync(address);

            GoogleAddress[] addresses = result.ToArray();
            Assert.Equal(type, addresses[0].Type);
        }
 public void CanParseAddressTypes(string address, GoogleAddressType type)
 {
     geoCoder.GeocodeAsync(address).ContinueWith(task =>
     {
         GoogleAddress[] addresses = task.Result.ToArray();
         Assert.Equal(type, addresses[0].Type);
     });
 }
		public void CanParseAddressTypes(string address, GoogleAddressType type)
		{
			geoCoder.GeocodeAsync(address).ContinueWith(task =>
			{
				GoogleAddress[] addresses = task.Result.ToArray();
				Assert.Equal(type, addresses[0].Type);
			});
		}
Exemplo n.º 5
0
        //public static List<GeocodeAddress> Geocoder(string address)
        //{
        //	List<GeocodeAddress> geocodeAddresses = new List<GeocodeAddress>();
        //	GoogleGeocoder geocoder = new GoogleGeocoder(ConfigurationManager.AppSettings["GoogleMapsApiKey"].ToString());
        //	IEnumerable<GoogleAddress> addresses = geocoder.Geocode(address).ToArray();

        //	if (addresses.Count() == 0)
        //	{
        //		geocodeAddresses.Add(new GeocodeAddress()
        //		{
        //			Status = GeocodeStatus.NotFound.ToString(),
        //			Source = "Google"
        //		});
        //		return geocodeAddresses;
        //	}

        //	foreach (GoogleAddress gaddress in addresses)
        //	{
        //		geocodeAddresses.Add(new GeocodeAddress()
        //		{
        //			Status = GoogleToGeocode[GoogleStatus.Ok].ToString(),
        //			Latitude = gaddress.Coordinates.Latitude,
        //			Longitude = gaddress.Coordinates.Longitude,
        //			Source = gaddress.Provider,
        //			SourceId = gaddress.PlaceId,
        //			FormattedAddress = gaddress.FormattedAddress,
        //			StreetNumber = GetComponentType(gaddress, GoogleAddressType.StreetNumber).LongName,
        //			StreetName = GetComponentType(gaddress, GoogleAddressType.Route).LongName,
        //			City = GetComponentType(gaddress, GoogleAddressType.Locality).LongName,
        //			County = GetComponentType(gaddress, GoogleAddressType.AdministrativeAreaLevel2).LongName,
        //			State = GetComponentType(gaddress, GoogleAddressType.AdministrativeAreaLevel1).LongName,
        //			Country = GetComponentType(gaddress, GoogleAddressType.Country).LongName,
        //			PostalCode = GetComponentType(gaddress, GoogleAddressType.PostalCode).LongName
        //		});
        //	}
        //          //Sleep the thread so we dont go over the limit per seconds with google maps.
        //          Thread.Sleep(100);
        //          return geocodeAddresses;
        //}

        public static GoogleAddressComponent GetComponentType(GoogleAddress address, GoogleAddressType type)
        {
            GoogleAddressComponent component;

            if ((component = address.Components.Where(w => w.Types.Contains(type)).SingleOrDefault()) != null)
            {
                return(component);
            }
            return(new GoogleAddressComponent(null, null, null));
        }
		public GoogleAddressComponent(GoogleAddressType[] types, string longName, string shortName)
		{
			if (types == null)
				throw new ArgumentNullException("types");

			if (types.Length < 1)
				throw new ArgumentException("Value cannot be empty.", "types");

			this.Types = types;
			this.LongName = longName;
			this.ShortName = shortName;
		}
Exemplo n.º 7
0
		public GoogleAddress(GoogleAddressType type, string formattedAddress, GoogleAddressComponent[] components, Location coordinates, bool isPartialMatch)
			: base(formattedAddress, coordinates, "Google")
		{
			if (components == null)
				throw new ArgumentNullException("components");

			if (components.Length < 1)
				throw new ArgumentException("Value cannot be empty.", "components");

			this.type = type;
			this.components = components;
			this.isPartialMatch = isPartialMatch;
		}
Exemplo n.º 8
0
        public GoogleAddress(GoogleAddressType type, string formattedAddress, GoogleAddressComponent[] components, Location coordinates, GoogleViewport viewport, bool isPartialMatch)
            : base(formattedAddress, coordinates, "Google")
        {
            if (components == null)
            {
                throw new ArgumentNullException("components");
            }

            this.type           = type;
            this.components     = components;
            this.isPartialMatch = isPartialMatch;
            this.viewport       = viewport;
        }
Exemplo n.º 9
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;
	    }
Exemplo n.º 10
0
        public GoogleAddress(GoogleAddressType type, string formattedAddress, GoogleAddressComponent[] components, Location coordinates, bool isPartialMatch)
            : base(formattedAddress, coordinates, "Google")
        {
            if (components == null)
            {
                throw new ArgumentNullException("components");
            }

            if (components.Length < 1)
            {
                throw new ArgumentException("Value cannot be empty.", "components");
            }

            this.type           = type;
            this.components     = components;
            this.isPartialMatch = isPartialMatch;
        }
Exemplo n.º 11
0
 public void CanParseAddressTypes(string address, GoogleAddressType type)
 {
     GoogleAddress[] addresses = geocoder.Geocode(address).ToArray();
     Assert.Equal(type, addresses[0].Type);
 }
Exemplo n.º 12
0
		public void CanParseAddressTypes(string address, GoogleAddressType type)
		{
			GoogleAddress[] addresses = geocoder.Geocode(address).ToArray();
			Assert.Equal(type, addresses[0].Type);
		}
Exemplo n.º 13
0
 public GoogleAddressComponent this[GoogleAddressType type]
 {
     get { return(Components.FirstOrDefault(c => c.Types.Contains(type))); }
 }
Exemplo n.º 14
0
		public GoogleAddressComponent this[GoogleAddressType type]
		{
			get { return Components.FirstOrDefault(c => c.Types.Contains(type)); }
		}
Exemplo n.º 15
0
        public async System.Threading.Tasks.Task <string> ReturnPostalAsync(string postal, GoogleAddressType type)
        {
            Debug.WriteLine("postal" + postal);
            GoogleGeocoder geocoder = new GoogleGeocoder();

            geocoder.ApiKey = "AIzaSyCY8FWydp6zky0N4TVk44x5xao2JjBFios";
            IEnumerable <GoogleAddress> addresses = await geocoder.GeocodeAsync("Singapore" + postal);

            Debug.WriteLine(addresses.First().Coordinates.Latitude + ": :" + addresses.First().Coordinates.Longitude);
            IEnumerable <GoogleAddress> reverse = await geocoder.ReverseGeocodeAsync(addresses.First().Coordinates.Latitude, addresses.First().Coordinates.Longitude);

            Debug.WriteLine(addresses.First().FormattedAddress);
            Debug.WriteLine(reverse.First().FormattedAddress);
            return(reverse.First().FormattedAddress);
        }