Geocoding.Google.GoogleGeocoder.Geocode C# (CSharp) Method

Geocode() public method

public Geocode ( string address ) : IEnumerable
address string
return IEnumerable
		public IEnumerable<GoogleAddress> Geocode(string address)
		{
			if (string.IsNullOrEmpty(address))
				throw new ArgumentNullException("address");

			HttpWebRequest request = BuildWebRequest("address", HttpUtility.UrlEncode(address));
			return ProcessRequest(request);
		}

Usage Example

        public void GetGeoCode(Classmate entity)
        {
            if (entity != null && entity.HomeAddress == string.Empty)
            {
                entity.Lat = string.Empty;
                entity.Lng = string.Empty;
                return;
            }
            System.Threading.Thread.Sleep(200); // wait a bit to avoid over limit error

            try
            {
                IGeocoder geocoder = new GoogleGeocoder();
                IEnumerable<Address> addresses = geocoder.Geocode(entity.HomeAddress);

                if (addresses.Count() > 0)
                {
                    entity.Lat = addresses.First().Coordinates.Latitude.ToString();
                    entity.Lng = addresses.First().Coordinates.Longitude.ToString();
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
All Usage Examples Of Geocoding.Google.GoogleGeocoder::Geocode