Beispiel #1
0
        public PlacesNearbySearchResponse NearbySearch(double lat, double lgn)
        {
            var response = new PlacesNearbySearchResponse();

            try
            {
                var AppKey = new ConfigurationBuilder().AddJsonFile("application.default.json").Build().GetSection("AppSettings")["ApiKey"];

                var request = new PlacesNearBySearchRequest
                {
                    Key      = AppKey.ToString(),//this.ApiKey,
                    Location = new Location()
                    {
                        Latitude = lat, Longitude = lgn
                    },
                    Radius = 1000
                };

                HttpEngine <PlacesNearBySearchRequest, PlacesNearbySearchResponse> httpResponse
                    = new HttpEngine <PlacesNearBySearchRequest, PlacesNearbySearchResponse>();

                response = httpResponse.Query(request);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Exception during geting places data: " +
                                ex.ToString());
            }
            return(response);
        }
        public PlacesNearbySearchResponse NearbySearchTest()
        {
            //Arrange
            var response = new PlacesNearbySearchResponse();
            var request  = new PlacesNearBySearchRequest
            {
                Key      = "AIzaSyB_4x15ATP7Br_fRJpb215UGhsL519cwPA",
                Location = new Location()
                {
                    Latitude = 45.8057017, Longitude = 15.9205017
                },
                Radius = 1000
            };

            HttpEngine <PlacesNearBySearchRequest, PlacesNearbySearchResponse> httpResponse
                = new HttpEngine <PlacesNearBySearchRequest, PlacesNearbySearchResponse>();

            // Act
            response = httpResponse.Query(request);

            // Assert
            Assert.IsNotNull(response);


            return(response);
        }
        private void AddPlaces(string keyword)
        {
            if (keyword == null)
            {
                keyword = "";
            }

            Task <PlacesNearbySearchResponse> task = wBll.GetWorkoutPlaces(keyword, coord);

            PlacesNearbySearchResponse response = task.Result;

            List <NearByResult> points = Enumerable.ToList(response.Results);

            AddMarkers(overlayOne, points);
        }
        private async Task <List <NearByResult> > GetNearByPlaces(double lat, double lng, string pageToken = null)
        {
            var nearByRequest = new PlacesNearBySearchRequest()
            {
                Key      = _googleApiKey,
                Location = new Location
                {
                    Latitude  = lat,
                    Longitude = lng
                },
                Type   = SearchPlaceType.Restaurant,
                Rankby = Ranking.Distance
            };

            if (!string.IsNullOrWhiteSpace(pageToken))
            {
                nearByRequest.PageToken = pageToken;
            }

            try
            {
                PlacesNearbySearchResponse nearByResponse = await GooglePlaces.NearBySearch.QueryAsync(nearByRequest);

                List <NearByResult> results = nearByResponse.Results.ToList();

                if (!string.IsNullOrWhiteSpace(nearByResponse.NextPageToken))
                {
                    await Task.Delay(2000);

                    results.AddRange(await GetNearByPlaces(lat, lng, nearByResponse.NextPageToken));
                }

                return(results);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private async void LoadTableContentAsync(List <WorkoutCategoryDetailDTO> wcList, List <ActivityLevelDetailDTO> alList)
        {
            this.Parent.Parent.Parent.Parent.Enabled = false;

            List <Task> tasks = new List <Task>();
            Dictionary <String, List <string> > keywords = new Dictionary <String, List <string> >();

            foreach (var item in wBll.GetWorkoutByWCAL(-1, -1))
            {
                string kw = wBll.ToPlacesKeyword(item.Name);
                if (kw == null)
                {
                    kw = "";
                }
                if (keywords.ContainsKey(kw))
                {
                    keywords[kw].Add(item.Name);
                }
                else
                {
                    keywords.Add(kw, new List <string> {
                        item.Name
                    });
                    Task <PlacesNearbySearchResponse> task = wBll.GetWorkoutPlaces(kw, coord);
                    tasks.Add(task);
                }
            }

            while (tasks.Count > 0)
            {
                Task finishedTask = await Task.WhenAny(tasks);

                int index = tasks.IndexOf(finishedTask);

                List <String> places = keywords.ElementAt(index).Value;

                Task <PlacesNearbySearchResponse> task     = finishedTask as Task <PlacesNearbySearchResponse>;
                PlacesNearbySearchResponse        response = task.Result;
                if (response.Results.Count() > 0)
                {
                    for (int k = 0; k < places.Count; k++)
                    {
                        Workout w = wBll.GetWorkout(places[k]);

                        Label lbl = new Label();
                        lbl.Text   = places[k];
                        lbl.Font   = new Font(lbl.Font.Name, 12f);
                        lbl.Height = (int)(lbl.Font.Size * 2.5);
                        lbl.Margin = new Padding(2);
                        lbl.Paint += FrmAddWorkoutPreferences.LblWorkout_Paint;
                        lbl.Click += lblWorkout_Click;
                        int yIndex = wcList.IndexOf(wcList.SingleOrDefault(wc => wc.ID == w.WorkoutCategoryID));
                        int xIndex = alList.IndexOf(alList.SingleOrDefault(al => al.ID == w.ActivityLevelID));

                        panelList[yIndex][xIndex].Controls.Add(lbl);
                    }
                }

                keywords.Remove(keywords.ElementAt(index).Key);
                tasks.Remove(finishedTask);
            }

            MessageBox.Show("load success");
            this.Parent.Parent.Parent.Parent.Enabled = true;
        }