public List <DataContracts.DC_Accommodation_NearbyPlaces> GetNearByPlacesByLatLng(DataContracts.DC_Address.DC_Address_GeoCodeForNearBy AG) { try { List <DataContracts.DC_Accommodation_NearbyPlaces> _lst = new List <DataContracts.DC_Accommodation_NearbyPlaces>(); string LatLng = String.Empty; LatLng = AG.Latitude.ToString() + "," + AG.Longitude.ToString(); DataContracts.DC_GeoLocation mapdata = null; var request = (HttpWebRequest)WebRequest.Create("https://maps.googleapis.com/maps/api/place/radarsearch/json?location=" + LatLng + "&radius=" + AG.radius + "&type=" + AG.PlaceType + "&key=" + System.Configuration.ConfigurationManager.AppSettings["GoogleKey"].ToString()); var proxyAddress = System.Configuration.ConfigurationManager.AppSettings["ProxyUri"]; if (System.Configuration.ConfigurationManager.AppSettings["ProxyUri"] != null) { WebProxy myProxy = new WebProxy(); Uri newUri = new Uri(proxyAddress); // Associate the newUri object to 'myProxy' object so that new myProxy settings can be set. myProxy.Address = newUri; // Create a NetworkCredential object and associate it with the // Proxy property of request object. //myProxy.Credentials = new NetworkCredential(username, password); request.Proxy = myProxy; } request.KeepAlive = false; HttpWebResponse response = request.GetResponse() as HttpWebResponse; if (response.StatusCode == HttpStatusCode.OK) //response.StatusDescription { Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); mapdata = JsonConvert.DeserializeObject <DataContracts.DC_GeoLocation>(responseFromServer); if (mapdata != null) { //using (ConsumerEntities context = new ConsumerEntities()) //{ // GoogleGeoCode GC = new GoogleGeoCode(); // GC.GoogleGeoCode_Id = Guid.NewGuid(); // GC.JobType = "ProductGeoLookup_ByLatLng"; // GC.Input = request.Address.AbsoluteUri; // GC.OutPut = responseFromServer; // context.GoogleGeoCodes.Add(GC); // context.SaveChanges(); //} } } //DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(DataContracts.DC_GeoLocation)); //var result = obj.ReadObject(dataStream) as DataContracts.DC_GeoLocation; response.Close(); return(_lst); } catch { throw new FaultException <DataContracts.DC_ErrorStatus>(new DataContracts.DC_ErrorStatus { ErrorMessage = "Error while searching address", ErrorStatusCode = System.Net.HttpStatusCode.InternalServerError }); } }
public List <DataContracts.DC_Accommodation_NearbyPlaces> GetNearByPlacesByLatLng(DataContracts.DC_Address.DC_Address_GeoCodeForNearBy AG) { using (BusinessLayer.BL_GeoLocation obj = new BL_GeoLocation()) { return(obj.GetNearByPlacesByLatLng(AG)); } }