private async Task FetchNearbyCoffee()
        {
            var location = await locations.GetGeopositionAsync();

            if (location == null)
            {
                // Error
                return;
            }

            SearchRecommendationFilters f = new SearchRecommendationFilters();

            f.intent = new SearchRecommendationIntent {
                id = "coffee"
            };

            var venues = await App.API.SearchRecommendations(f, location : FoursquareLocationFromGeoposition(location));

            if (venues.response != null)
            {
                VenueList.ItemsSource = venues.response.group.results.Select(r => r.venue);
            }

            Sticker.Visibility = Visibility.Collapsed;
            Shaker.Stop();
        }
示例#2
0
        public static void AddBrowseExploreParams(this FoursquareRequest req, SearchRecommendationFilters filters = null,
                                                  FoursquareLocation currentLocation = null, FoursquareLocation location = null, FoursquareLocation ne = null, FoursquareLocation sw = null,
                                                  string near = null, string nearGeoId = null)
        {
            if (filters != null)
            {
                if (!string.IsNullOrEmpty(filters.query))
                {
                    req.AddParam("query", filters.query);
                }
                if (filters.intent != null)
                {
                    req.AddParam("intent", filters.intent.id);
                }
                if (filters.subintent != null)
                {
                    req.AddParam("subintent", filters.subintent.id);
                }
                if (filters.openAt != null)
                {
                    if (filters.openAt.openNow)
                    {
                        req.AddParam("openNow", "1");
                    }
                    else if (filters.openAt.localDay >= 0 && !string.IsNullOrEmpty(filters.openAt.localTime))
                    {
                        req.AddParam("localDay", filters.openAt.localDay == 0 ? "7" : filters.openAt.localDay.ToString());
                        req.AddParam("localTime", filters.openAt.localTime);
                    }
                }
                if (filters.refinements != null && filters.refinements.Count > 0)
                {
                    var refinements = new Dictionary <string, string>();
                    for (int i = 0; i < filters.refinements.Count; i++)
                    {
                        SearchRecommendationRefinement item = filters.refinements[i];
                        if (!string.IsNullOrEmpty(item.groupType))
                        {
                            if (refinements.ContainsKey(item.groupType))
                            {
                                string val = refinements[item.groupType];
                                refinements[item.groupType] = val + "," + RefinementString(item, i);
                            }
                            else
                            {
                                refinements.Add(item.groupType, RefinementString(item, i));
                            }
                        }
                    }

                    foreach (var item in refinements.Keys)
                    {
                        req.AddParam(item, refinements[item]);
                    }
                }
            }

            if (ne == null && sw == null)
            {
                req.AddLocationParams(location);
                if (!string.IsNullOrEmpty(near))
                {
                    req.AddParam("near", near);
                    if (!string.IsNullOrEmpty(nearGeoId))
                    {
                        req.AddParam("nearGeoId", nearGeoId);
                    }
                }
            }
            else
            {
                req.AddParam("ne", LatLngFromLocation(ne));
                req.AddParam("sw", LatLngFromLocation(sw));
            }

            if (currentLocation != null)
            {
                req.AddParam("userll", LatLngFromLocation(currentLocation));
            }
        }
        public Task <FoursquareResponse <SearchRecommendation> > SearchRecommendations(SearchRecommendationFilters filters, RecommendationSort sort = RecommendationSort.BestMatch,
                                                                                       string near = null, string nearGeoId = null, int snippetCharLimit = Constants.BROWSE_EXPLORE_SNIPPET_LENGTH,
                                                                                       FoursquareLocation location   = null, FoursquareLocation currentLocation = null, FoursquareLocation ne = null, FoursquareLocation sw = null,
                                                                                       bool ignoreSpellingCorrection = false, int?searchRadius           = null, string mode = null, int limit = Constants.DEFAULT_PAGE_SIZE, int offset = 0,
                                                                                       List <string> excludeVenues   = null, List <string> includeVenues = null, string referralId = null, SearchRecommendationLocations.SearchRecommendationGeoBounds bounds = null,
                                                                                       int initialOffset             = 0)
        {
            var req = new FoursquareRequest(ApiBase + "search/recommendations");

            if (searchRadius.HasValue)
            {
                req.AddParam("radius", searchRadius.GetValueOrDefault(0).ToString());
            }
            req.AddParam("snippetCharacterLimit", snippetCharLimit.ToString());
            switch (sort)
            {
            case RecommendationSort.Distance:
                req.AddParam("sortByDistance", "1");
                break;

            case RecommendationSort.Rating:
                req.AddParam("sortByVenueRating", "1");
                break;
            }

            if (!string.IsNullOrEmpty(mode))
            {
                req.AddParam("mode", mode);
            }
            if (excludeVenues != null && excludeVenues.Count > 0)
            {
                req.AddParam("excludeVenues", string.Join(",", excludeVenues));
            }
            if (includeVenues != null && includeVenues.Count > 0)
            {
                req.AddParam("includeVenues", string.Join(",", includeVenues));
            }
            if (ignoreSpellingCorrection)
            {
                req.AddParam("noCorrect", "1");
            }
            if (initialOffset > 0)
            {
                req.AddParam("initialOffset", initialOffset.ToString(CultureInfo.InvariantCulture));
            }

            req.AddParam("limit", limit.ToString());
            req.AddParam("offset", offset.ToString());
            req.AddParam("referralId", referralId);

            req.AddBrowseExploreParams(filters, currentLocation, location, ne, sw, near, nearGeoId);

            if (bounds != null)
            {
                if (bounds.box != null)
                {
                    req.AddParam("fromGeoBounds", "true");
                    req.AddParam("ne", ApiUtils.LatLngFromLocation(new FoursquareLocation {
                        Lat = bounds.box.ne.lat, Lng = bounds.box.ne.lng
                    }));
                    req.AddParam("sw", ApiUtils.LatLngFromLocation(new FoursquareLocation {
                        Lat = bounds.box.sw.lat, Lng = bounds.box.sw.lng
                    }));
                }
                else if (bounds.circle != null)
                {
                    req.AddParam("fromGeoBounds", "true");
                    req.AddParam("radius", bounds.circle.radius.ToString(CultureInfo.InvariantCulture));
                }
                else if (!string.IsNullOrEmpty(bounds.geoId))
                {
                    req.AddParam("fromGeoBounds", "true");
                }
            }

            AddCommonParams(ref req);
            return(req.MakeRequest <SearchRecommendation>());
        }