Example #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);
        }
Example #2
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);
        }