Ejemplo n.º 1
0
        public async static Task <List <Venue> > GetVenues(double lat, double lon)
        {
            List <Venue> venues = new List <Venue>();

            var url = VenueRoot.GenerateURL(lat, lon);

            using (HttpClient client = new HttpClient())
            {
                var responsee = await client.GetAsync(url);

                var json = await responsee.Content.ReadAsStringAsync();

                var jsonConverted = JsonConvert.DeserializeObject <VenueRoot>(json);
                venues = jsonConverted.response.venues.ToList();
            }

            return(venues);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get list of nearby venues from FourSquare search API
        /// Refactored inside Venue class for MVVM
        /// </summary>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <returns></returns>
        public async static Task <List <Venue> > GetVenues(double latitude, double longitude) // return a list of Venues, for a given location
        {                                                                                     // had to be static as 'await' used below, and had to be Task<> as returning non-void in an async
            List <Venue> venues = new List <Venue>();

            var url = VenueRoot.GenerateURL(latitude, longitude);

            using (HttpClient client = new HttpClient())
            {
                var response = await client.GetAsync(url);

                var json = await response.Content.ReadAsStringAsync();

                var venueRoot = JsonConvert.DeserializeObject <VenueRoot>(json);
                // Use NewtonSoft JSON plugin to deserialize await'd json response

                venues = venueRoot.response.venues as List <Venue>;      // here will be a list of Venue objects
            }

            return(venues);
        }