Пример #1
0
        public List <GooglePlace> DetailedSearchForNearestPlaces(Dictionary <string, string> addToMainUrl)
        {
            GetLocationService ip = new GetLocationService();

            addToMainUrl.Add("key", APIKey);
            addToMainUrl.Add("location", ip.GetLocation());
            addToMainUrl.Add("radius", "1000");

            string Url = BuildUrl(BaseUrl, addToMainUrl);

            using (HttpClient client = new HttpClient())
            {
                var strResult = client.GetStringAsync(Url).Result;
                var result    = JsonConvert.DeserializeObject <GooglePlacesAPIRespone>(strResult);
                return(result.Results);
            }
        }
Пример #2
0
        public List <GooglePlace> FindNearestPlacesByCategory(string category)
        {
            GetLocationService ip       = new GetLocationService();
            string             radius   = "1000";
            string             location = ip.GetLocation();


            string Url = BuildUrl(BaseUrl, new Dictionary <string, string>()
            {
                { "key", APIKey },
                { "type", category },
                { "location", location },
                { "radius", radius },
                //{"opennow","true"}
            });

            try
            {
                string strResult = string.Empty;
                using (HttpClient client = new HttpClient())
                {
                    try
                    {
                        strResult = client.GetStringAsync(Url).Result;
                    }
                    catch (System.Exception)
                    {
                        MessageBox.Show("Connection Error, check you internet connection and try again later");
                        return(new List <GooglePlace>());
                    }

                    var result = JsonConvert.DeserializeObject <GooglePlacesAPIRespone>(strResult);
                    return(result.Results);
                }
            }
            catch (HttpRequestException)
            {
                MessageBox.Show("Connection Error, check you internet connection and try again later");
                return(null);
            }
        }