Ejemplo n.º 1
0
 public StorePrice(StoreInfo aStoreInfo)
 {
     this.Distance = aStoreInfo.Distance;
     //this.Duration = aStoreInfo.Duration;
     //this.IsOpenNow = aStoreInfo.IsOpenNow;
     this.Latitude = aStoreInfo.Latitude;
     this.Longitude = aStoreInfo.Longitude;
     this.StoreAddress = aStoreInfo.StoreAddress;
     this.StoreID = aStoreInfo.StoreID;
     this.StoreName = aStoreInfo.StoreName;
 }
Ejemplo n.º 2
0
        public IHttpActionResult getStoreInfo(double Latitude, double Longitude)
        {
            StoreInfo SI=new StoreInfo();
            List<StoreInfo> lstSI = new List<StoreInfo>();
            //lstSI = locationService.getStores(Latitude, Longitude, 0.2); // Radius is ~150 feet. to accomadate if the user in parking lots...
            lstSI = storeService.getStoresInRadius(Latitude, Longitude, 0.2); // Radius is ~150 feet. to accomadate if the user in parking lots...
            //TODO:Insert into stores table
            if (lstSI.Count > 0)
                SI = lstSI[0];

            return Ok(SI);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This Function generates a list of StoreInfo objects.
        /// <param name="Latitude">Current Latitude</param>
        /// <param name="Longitude">Current Longitude</param>
        /// <param name="Radius">Radius in Miles</param>
        /// <returns> List of StoreInfo Objects</returns>
        /// 
        public List<StoreInfo> getStores(double Latitude, double Longitude, double Radius)
        {
            List<StoreInfo> lstSI = new List<StoreInfo>();

            //TODO: Add the storeID

            // Generating Parameters for Google Places API
            NameValueCollection GP_Details = new NameValueCollection();
            String googleAPIKey = appSettingsService.GetGoogleAPIKey();
            GP_Details.Add("key", googleAPIKey);
            GP_Details.Add("sensor", "false");
            GP_Details.Add("location", Latitude + "," + Longitude);
            GP_Details.Add("radius", Convert.ToString(Radius * 1609)); // Radius is converted to meters for the API
            GP_Details.Add("types", "liquor_store");

            string GP_Url = "json?" + string.Join("&", GP_Details.AllKeys.Select(x => string.Format("{0}={1}", HttpUtility.UrlEncode(x), HttpUtility.UrlEncode(GP_Details[x]))));

            HttpClient httpGPClient = new HttpClient();
            httpGPClient.BaseAddress = new Uri("https://maps.googleapis.com/maps/api/place/search/");
            HttpResponseMessage GP_Response = httpGPClient.GetAsync(GP_Url).Result;
            if (GP_Response.IsSuccessStatusCode)
            {

                string googleResult = GP_Response.Content.ReadAsStringAsync().Result.ToString();
                // parsing Data out of JSON result from google places API
                JObject json = Newtonsoft.Json.Linq.JObject.Parse(googleResult);
                JArray results = (JArray)json["results"];
                for (int i = 0; i < results.Count; i++)
                {
                    StoreInfo si = new StoreInfo();
                    JToken location = json["results"][i]["geometry"]["location"];
                    si.Latitude = location["lat"].Value<double>();
                    si.Longitude = location["lng"].Value<double>();

                    si.StoreName = json["results"][i]["name"].Value<string>();
                    si.StoreAddress = json["results"][i]["vicinity"].Value<string>();

                    JToken hours = json["results"][i]["opening_hours"];
                    //if (hours != null)
                       // si.IsOpenNow = hours["open_now"].Value<bool>();

                    // Generating parameters for Google Matrix API to find the distance and the duration
                    //NameValueCollection GM_Details = new NameValueCollection();
                    //GM_Details.Add("key", googleAPIKey);
                    //GM_Details.Add("origins", Latitude + "," + Longitude);
                    //GM_Details.Add("destinations", si.Latitude + "," + si.Longitude);
                    //GM_Details.Add("units", "imperial");

                    //string GM_Url = "json?" + string.Join("&", GM_Details.AllKeys.Select(x => string.Format("{0}={1}", HttpUtility.UrlEncode(x), HttpUtility.UrlEncode(GM_Details[x]))));

                    //HttpClient httpGMClient = new HttpClient();
                    //httpGMClient.BaseAddress = new Uri("https://maps.googleapis.com/maps/api/distancematrix/");
                    //HttpResponseMessage GM_Response = httpGMClient.GetAsync(GM_Url).Result;
                    //if (GM_Response.IsSuccessStatusCode)
                    //{
                    //    //Parsing out the distance and duration out of the JSON from Google Matrix API.
                    //    string googleMatrixResult = GM_Response.Content.ReadAsStringAsync().Result.ToString();

                    //    JObject GM_Json = Newtonsoft.Json.Linq.JObject.Parse(googleMatrixResult);
                    //    JArray rows = (JArray)GM_Json["rows"];
                    //    if (rows.Count > 0)
                    //    {
                    //        si.Distance = GM_Json["rows"][0]["elements"][0]["distance"]["value"].Value<double>();
                    //        si.Duration = GM_Json["rows"][0]["elements"][0]["duration"]["value"].Value<double>();
                    //    }
                    //}
                    Dictionary<String, Double> distanceResult = getDistanceAndTime(Latitude, Longitude, si.Latitude, si.Longitude);
                    si.Distance = distanceResult["Distance"];

                    //si.Duration = distanceResult["Duration"];

                    lstSI.Add(si);
                }

            }
            lstSI = lstSI.OrderBy(o => o.Distance).ToList();
            return lstSI;
        }