/// <summary>
        /// Searches for nearest venues based on provided location. If authenticated user, gets venues with friend's checkins
        /// </summary>
        /// <param name="location">location where to search for venues</param>
        /// <param name="accessToken">access token of authenticated user</param>
        /// <returns>List of nearest places</returns>
        public List <FPlace> SearchPlaces(Models.Location location, string accessToken)
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }

            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("ll", location.ToString());
            parameters.Add("limit", "50");
            parameters.Add("radius", "5000");

            List <Checkin> friendsCheckins = GetFriendsRecentCheckins(accessToken);
            List <Venue>   venues          = null;

            try
            {
                venues = sharpSquare.SearchVenues(parameters);
            }
            catch (WebException webEx)
            {
                throw new InvalidOperationException("Bad location data");
            }

            return(TransformerHelpers.TransformToFPlaces(venues, friendsCheckins));
        }
        public List <Venue> SearchVenues(string location)
        {
            var venues = _FourSquare.SearchVenues(new Dictionary <string, string>
            {
                { "near", location },
                { "query", location }
            });

            return(venues);
        }
        private List <Venue> GetBarData(string latitude, string longitude, string radius)
        {
            var sharpSquare = new SharpSquare(clientId, clientSecret);

            // let's build the query
            Dictionary <string, string> parameters = new Dictionary <string, string>
            {
                { "ll", latitude + "," + longitude }, // Coords
                { "radius", radius },
                { "categoryId", categoryIdBar }
            };

            return(sharpSquare.SearchVenues(parameters));
        }
Example #4
0
        public async Task <List <Venue> > GetVenues(double latitude, double longitude, double radius, string query)
        {
            var parameters = new Dictionary <string, string>
            {
                { "ll", $"{latitude:F7},{longitude:F7}" },
                { "radius", $"{radius:F0}" },
                { "query", query }
            };

            var venuesTask = new Task <List <Venue> >(() => _sharpSquare.SearchVenues(parameters));

            venuesTask.Start();

            return(await venuesTask);
        }
        public ActionResult AdicionarTips()
        {
            SharpSquare sharpSquare = new SharpSquare(clientId, clientSecret);
            List<Banco.Models.Tip> tiplist = new List<Banco.Models.Tip>();
            List<Banco.Models.User> userlist = new List<Banco.Models.User>();
            List<Banco.Models.Venue> venuelist = new List<Banco.Models.Venue>();
            Dictionary<string, string> parametros = new Dictionary<string, string>();
            List<FourSquare.SharpSquare.Entities.Venue> venues = new List<FourSquare.SharpSquare.Entities.Venue>();
            List<FourSquare.SharpSquare.Entities.Tip> tips = new List<FourSquare.SharpSquare.Entities.Tip>();
            parametros.Add("limit", "500"); // tentando pegar ateh 500 venues e tips

            for (double lon = -43.2652; lon < -43.2475; lon += 0.0005)
            {

                parametros.Remove("limit");
                parametros.Add("limit", "50");
                parametros.Add("ll", "-22.8707," + lon.ToString().Replace(',', '.'));
                venues = sharpSquare.SearchVenues(parametros);

                foreach (FourSquare.SharpSquare.Entities.Venue v in venues)
                {
                    Banco.Models.Venue ven;
                    ven = db.Venues.FirstOrDefault(f => f.SquareId == v.id);
                    if (ven == null && venuelist.FirstOrDefault(f => f.SquareId == v.id) == null)
                    {
                        ven = new Banco.Models.Venue();
                        ven.SquareId = v.id;
                        ven.lat = -22.8707;
                        ven.lon = lon;
                        venuelist.Add(ven);
                        db.Venues.Add(ven);
                    }
                    ven.Name = v.name;
                    parametros.Remove("ll");
                    parametros.Remove("limit");
                    parametros.Add("limit", "500");
                    tips = sharpSquare.GetVenueTips(v.id, parametros);
                    foreach (FourSquare.SharpSquare.Entities.Tip t in tips)
                    {
                        Banco.Models.Tip tip;
                        //Verifica de tip já foi adicionada anteriormente no banco
                        tip = db.Tips.FirstOrDefault(f => f.SquareId == t.id);
                        if (tip == null && tiplist.FirstOrDefault(f => f.SquareId == t.id) == null)
                        {
                            //Se é uma tip nova cria uma e adiciona no context
                            tip = new Banco.Models.Tip();
                            tip.SquareId = t.id;
                            tip.Venue = ven;
                            tiplist.Add(tip);
                            db.Tips.Add(tip);

                        }
                        //sendo tip nova ou não atualiza os campos
                        tip.Description = t.text;
                        Banco.Models.User user;
                        user = db.Users.FirstOrDefault(f => f.SquareId == t.user.id);
                        if (user == null && userlist.FirstOrDefault(f => f.SquareId == t.user.id) == null)
                        {
                            user = new Banco.Models.User();
                            user.SquareId = t.user.id;
                            user.Name = t.user.firstName;
                            userlist.Add(user);
                            db.Users.Add(user);
                        }
                        if (user == null && userlist.FirstOrDefault(f => f.SquareId == t.user.id) != null)
                        {
                            user = userlist.FirstOrDefault(f => f.SquareId == t.user.id);
                        }
                        tip.User = user;
                    }
                }
                db.SaveChanges();
            }
            ViewBag.Message = "Venues, tips e users adicionados ao banco com sucesso.";
            return View();
        }
    public List<FourSquareDataModel.Venue> GetVenuesNearBuilding(string modelId, string buildingId)
    {
      if (!IW360OAuth.IsAuthorized) return null;
      Building building = GetModelBuilding(modelId, buildingId);
      if (building.geometry.Type != AiwGeometryType.Polygon) return null;

      // from the polygon of the building on IW360,
      // let calculate the center point (avarage)
      AiwPolygon pl = building.geometry as AiwPolygon;
      int i = 0;
      double avarageLat = 0;
      double avarageLng = 0;
      foreach (AiwLineString ls in pl.LinearRings)
      {
        foreach (AiwCoordinate coord in ls.Coordinates)
        {
          avarageLat += coord.Y;
          avarageLng += coord.X;
          i++;
        }
      }
      avarageLat /= i;
      avarageLng /= i;

      // now use the avarage point to get venus from Four Square
      SharpSquare square = new SharpSquare(FOURSQUARE_CLIENTID, FOURSQUARE_CLIENTSECRET);
      Dictionary<string, string> requestParams = new Dictionary<string, string>();
      requestParams.Add("ll", string.Format(new CultureInfo("en-US"), "{0},{1}", avarageLat, avarageLng));
      requestParams.Add("radius", "500");
      requestParams.Add("intent", "browse");
      List<Venue> venues = square.SearchVenues(requestParams);

      // the venus from Four Square will come with lots of data
      // let's simplify and add some interesting data
      List<FourSquareDataModel.Venue> simplifiedVenues = new List<FourSquareDataModel.Venue>();
      foreach (Venue v in venues)
      {
        FourSquareDataModel.Venue venueSummary = new FourSquareDataModel.Venue();
        venueSummary.name = v.name;
        venueSummary.id = v.id;
        venueSummary.distance = v.location.distance;
        venueSummary.address = v.location.address;
        venueSummary.url = v.url;
        venueSummary.foursqlat = v.location.lat;
        venueSummary.foursqlng = v.location.lng;
        venueSummary.iw360lat = avarageLat;
        venueSummary.iw360lng = avarageLng;

        simplifiedVenues.Add(venueSummary);
      }

      // and finally order by distance from the center of the building
      var simplifiedVenuesOrder = from FourSquareDataModel.Venue v in simplifiedVenues orderby v.distance ascending select v;

      return simplifiedVenuesOrder.ToList(); // will serialize to JSON
    }
        private List<Venue> GetVenues(SharpSquare sharpSquare, string latitude, string longitude, string type)
        {
            var parameters = new Dictionary<string, string>
                                 {
                                     {"ll", string.Join(",", latitude, longitude)},
                                     {"categoryId", m_eventTypes[type.ToLower()]}
                                 };

            return sharpSquare.SearchVenues(parameters);
        }