Пример #1
0
        public List <GPlace> GetPlaceList(string strQuery, int limit)
        {
            List <GPlace> gPlaces = new List <GPlace>();

            //call request method for Google Places
            var queryParams = new Dictionary <string, string>()
            {
                { "query", strQuery },
                { "key", GPlaces_api_key }
            };

            JObject _placesStrReturned = Perform_Request_JSON(GPlaces_Url + "textsearch/json", queryParams);

            //Get List of Results(Places)
            var results = ((dynamic)_placesStrReturned).results;
            var i       = 0;

            foreach (var _place in results)
            {
                var _pl = (dynamic)_place;

                GPlace gPlace = new GPlace();
                gPlace.formattedAddress = _pl["formatted_address"];
                gPlace.name             = _pl["name"];
                gPlace.iconURL          = _pl["icon"];
                gPlace.place_id         = _pl["place_id"];

                //Get Photo Listing with photo_reference's
                var _photos = _pl.photos;
                if (_photos != null)
                {
                    foreach (var _photo in _photos)
                    {
                        string _photoRefID = _photo["photo_reference"];

                        //add photoRef to collection
                        gPlace.photos.Add(_photoRefID);

                        //add actual photo url to collection
                        string photoURL = GetGPhotoUrl(_photoRefID, "100");

                        GPlacePhotoUrls gPlacePhotoUrl = new GPlacePhotoUrls();
                        gPlacePhotoUrl.place_id = gPlace.place_id;
                        gPlacePhotoUrl.photoUrl = photoURL;

                        gPlace.photoUrls.Add(gPlacePhotoUrl);
                    }
                }
                gPlaces.Add(gPlace);

                i += 1;
                if (i > limit)
                {
                    return(gPlaces);
                }
            }

            return(gPlaces);
        }
Пример #2
0
        private List <FavPl_GPlace> GetFavGPlaces(List <FavoritePlaces> myfavoritePlaces)
        {
            GoogleAPIs          gapi          = new GoogleAPIs();
            List <GPlace>       gPlaces       = new List <GPlace>();
            List <FavPl_GPlace> favPl_GPlaces = new List <FavPl_GPlace>();
            bool favsAreEqual = true;

            //favsAreEqual = CheckFavPlSessionChanged(myfavoritePlaces, favsAreEqual);

            favsAreEqual = false;//do this to force refresh

            if (Session["gPlaces"] != null && Session["filteredModel"] != null && favsAreEqual)
            {
                favPl_GPlaces = (List <FavPl_GPlace>)Session["favPl_GPlaces"];
            }
            else
            {
                //for each Favorite Place, get Place info from Google API and add to gPlaces list.
                foreach (FavoritePlaces fp in myfavoritePlaces)
                {
                    if (fp.GPlace_Id != null && fp.GPlace_Id != "0")
                    {
                        //get place infor from google api
                        GPlace gplace = new GPlace();
                        gplace = gapi.GetPlaceDetails(fp.GPlace_Id);

                        FavPl_GPlace favPl_Gplace = new FavPl_GPlace();
                        favPl_Gplace.FavoritePlaceID = fp.ID;
                        try
                        {
                            favPl_Gplace.GPhotoUrl = gplace.photoUrls.FirstOrDefault().photoUrl;
                        }
                        catch (Exception ex)
                        {
                        }

                        favPl_Gplace.GPlaceID   = gplace.place_id;
                        favPl_Gplace.GPlaceName = gplace.name;
                        favPl_Gplace.href       = "/places/details/" + gplace.place_id;

                        favPl_GPlaces.Add(favPl_Gplace);
                    }
                }

                //store session objects
                Session["myfavoritePlaces"] = favPl_GPlaces;
            }
            return(favPl_GPlaces);
        }
Пример #3
0
        public GPlace GetPlaceDetails(string _placeid)
        {
            //call request method for Google Places
            var queryParams = new Dictionary <string, string>()
            {
                { "placeid", _placeid },
                { "key", GPlaces_api_key }
            };

            //Get Google Photo Details
            JObject _placeReturned = Perform_Request_JSON(GPlaces_Url + "details" + "/json", queryParams);

            var _pl = ((dynamic)_placeReturned).result;

            GPlace gPlace = new GPlace();

            gPlace.formattedAddress = _pl["formatted_address"];
            gPlace.name             = _pl["name"];
            gPlace.iconURL          = _pl["icon"];
            gPlace.place_id         = _pl["place_id"];
            gPlace.website_url      = _pl["website"];

            //load photoUrls for place
            if (_pl.photos != null)
            {
                foreach (var p in _pl.photos)
                {
                    string _photoRefID = p["photo_reference"];

                    //Get Google Photo Url
                    string photoURL = GetGPhotoUrl(_photoRefID, "200");

                    GPlacePhotoUrls gPUrl = new GPlacePhotoUrls();
                    gPUrl.place_id = _placeid;
                    gPUrl.photoUrl = photoURL;

                    gPlace.photoUrls.Add(gPUrl);
                }
            }

            return(gPlace);
        }
Пример #4
0
        // GET: Places/Details/5
        //public ActionResult Details(int? id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    Place place = db.Place.Find(id);
        //    if (place == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    return View(place);
        //}

        public ActionResult Details(string id)
        {
            if (config.UID == null)
            {
                //user is not logged in
                return(RedirectToAction("Login", "Account"));
            }

            if (string.IsNullOrEmpty(id))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            else
            {
                GPlace     gPlace = new GPlace();
                GoogleAPIs gapi   = new GoogleAPIs();

                //hydrate gPlace
                gPlace = gapi.GetPlaceDetails(id);

                Place place = new Place();
                place.GPlace_Id   = gPlace.place_id;
                place.Name        = gPlace.name;
                place.Address     = gPlace.formattedAddress;
                place.Description = gPlace.website_url;

                //photos
                foreach (GPlacePhotoUrls gPlPhotoUrl in gPlace.photoUrls)
                {
                    PlaceMedia pMedia = new PlaceMedia();

                    pMedia.path = gPlPhotoUrl.photoUrl.ToString();

                    place.PlaceMedia.Add(pMedia);
                }

                return(View(place));
            }
        }
Пример #5
0
        private ActionResult GetFavGPlaces(List <FavoritePlaces> myfavoritePlaces)
        {
            GoogleAPIs    gapi         = new GoogleAPIs();
            List <GPlace> gPlaces      = new List <GPlace>();
            bool          favsAreEqual = true;

            //if (Session["myfavoritePlaces"] != null)
            //{
            //    List<FavoritePlaces> sMyFavoritePlaces = (List<FavoritePlaces>)Session["myfavoritePlaces"];

            //    if (sMyFavoritePlaces != null)
            //    {
            //        foreach (FavoritePlaces f_db in myfavoritePlaces)
            //        {
            //            var found = sMyFavoritePlaces.Where(m => m.GPlace_Id == f_db.GPlace_Id);
            //            if (found == null)
            //            {
            //                favsAreEqual = false;
            //            }
            //        }
            //    }
            //}
            //else
            //{
            //    favsAreEqual = false;
            //}

            favsAreEqual = false;

            if (Session["gPlaces"] != null && Session["filteredModel"] != null && favsAreEqual)
            {
                //return data to view
                ViewBag.gPlaces = (List <GPlace>)Session["gPlaces"];
                return(View((List <FavoritePlaces>)Session["filteredModel"]));
            }
            else
            {
                //for each Favorite Place, get Place info from Google API and add to gPlaces list.
                foreach (FavoritePlaces fp in myfavoritePlaces)
                {
                    GPlace gp = new GPlace();
                    if (fp.GPlace_Id != null && fp.GPlace_Id != "0")
                    {
                        gp = gapi.GetPlaceDetails(fp.GPlace_Id);
                        gPlaces.Add(gp);
                    }
                }

                //match gPlaces from API call returns to FavoritePlaces data from db
                List <FavoritePlaces> filteredModel = new List <FavoritePlaces>();
                foreach (GPlace gp in gPlaces)
                {
                    if (myfavoritePlaces.Where(g => g.GPlace_Id == gp.place_id).Count() > 0)
                    {
                        filteredModel.Add(myfavoritePlaces.Where(g => g.GPlace_Id == gp.place_id).FirstOrDefault());
                    }
                }

                //store session objects
                //Session["gPlaces"] = gPlaces;
                //Session["filteredModel"] = filteredModel;
                //Session["myfavoritePlaces"] = myfavoritePlaces;

                //return data to view
                ViewBag.gPlaces = gPlaces;
                return(View(filteredModel));
            }
        }