public static async Task <dynamic> GetMapsGoogleResponse(string address) { using (var client = new HttpClient()) { Uri uri = new Uri(string.Format("http://maps.google.com/maps/api/geocode/json?address={0}", address)); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = new HttpResponseMessage(); response = await client.GetAsync(uri); response.EnsureSuccessStatusCode(); var result = response.Content.ReadAsStringAsync().Result; return(JsonUtils.ConvertToObject(result)); } }
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //::: ::: //::: This routine calculates the distance between two points (given the ::: //::: latitude/longitude of those points). It is being used to calculate ::: //::: the distance between two locations using GeoDataSource(TM) products ::: //::: ::: //::: Definitions: ::: //::: South latitudes are negative, east longitudes are positive ::: //::: ::: //::: Passed to function: ::: //::: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) ::: //::: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) ::: //::: unit = the unit you desire for results ::: //::: where: 'M' is statute miles (default) ::: //::: 'K' is kilometers ::: //::: 'N' is nautical miles ::: //::: ::: //::: Worldwide cities and other features databases with latitude longitude ::: //::: are available at http://www.geodatasource.com ::: //::: ::: //::: For enquiries, please contact [email protected] ::: //::: ::: //::: Official Web site: http://www.geodatasource.com ::: //::: ::: //::: GeoDataSource.com (C) All Rights Reserved 2015 ::: //::: ::: //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //189.61.220.247 public static async Task <Address> GetAddressByIp(string ip) { using (var client = new HttpClient()) { Uri uri = new Uri(string.Format("http://freegeoip.net/json/{0}", ip)); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = new HttpResponseMessage(); response = await client.GetAsync(uri); response.EnsureSuccessStatusCode(); dynamic result = JsonUtils.ConvertToObject(response.Content.ReadAsStringAsync().Result); return(new Address { City = result.city, State = result.region_code }); } }