private async void FeatureLocationList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            GooglePlaceIdModel model = (GooglePlaceIdModel)e.AddedItems[0];

            if (model != null)
            {
                GoogleMapPlaceModel returnModel = await ConvertPlaceIdToAddress(model);

                //Debug.WriteLine(model.result.geometry.location.lat);
                OutdoorModel m = new OutdoorModel()
                {
                    longitude = returnModel.result.geometry.location.lng.ToString(),
                    latitude  = returnModel.result.geometry.location.lat.ToString()
                };
                Debug.WriteLine(m.longitude);
                Debug.WriteLine(m.latitude);

                this.Frame.Navigate(typeof(ElderlyOutdoorLocationMap), m);
            }
        }
        private async Task <GoogleMapPlaceModel> ConvertPlaceIdToAddress(GooglePlaceIdModel m)
        {
            progressbar.Visibility = Visibility.Visible;

            try
            {
                HttpClient httpClient = new HttpClient();
                var        response   = await httpClient.GetAsync(_GOOGLE_AUTOCOMPLETE_URL + "placeid=" + m.placeid + "&key=" + GoogleMapKey);

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    GoogleMapPlaceModel model = JsonConvert.DeserializeObject <GoogleMapPlaceModel>(content);
                    //model.count = m.count;
                    return(model);

                    //SearchResultPlaceList.ItemsSource = foundPlaceModel.predictions;
                }
                else
                {
                    progressbar.Visibility = Visibility.Collapsed;
                    MessageDialog md = new MessageDialog("Error occur search place...try again later...");
                    await md.ShowAsync();

                    return(null);
                }
            }
            catch
            {
                progressbar.Visibility = Visibility.Collapsed;
                MessageDialog md = new MessageDialog("Error occur search place...try again later...");
                await md.ShowAsync();

                return(null);
            }
        }
        private async void LoadLocationList(string elderlyId)
        {
            progressbar.Visibility = Visibility.Visible;

            Object api = settings.Values["api"];
            Object id  = settings.Values["userid"];

            if (api != null && id != null)
            {
                try
                {
                    HttpClient httpClient = new HttpClient();
                    var        response   = await httpClient.GetAsync(common.getIP() + "api/featuredlocation/" + api.ToString() + "/" + id.ToString() + "/" + elderlyId);

                    if (response.IsSuccessStatusCode)
                    {
                        string content = await response.Content.ReadAsStringAsync();

                        List <OutdoorModel> outdoormodels = JsonConvert.DeserializeObject <List <OutdoorModel> >(content);

                        List <GooglePlaceIdModel> groupPlaces = new List <GooglePlaceIdModel>();

                        foreach (var a in outdoormodels)
                        {
                            string place_id = a.placeid;

                            if (groupPlaces.Count == 0)
                            {
                                List <OutdoorModel> l = new List <OutdoorModel>();
                                l.Add(a);

                                GooglePlaceIdModel newModel = new GooglePlaceIdModel()
                                {
                                    placeid       = a.placeid,
                                    placeaddress  = a.placeaddress,
                                    outdoorModels = l
                                };

                                groupPlaces.Add(newModel);
                            }
                            else
                            {
                                bool added = false;

                                foreach (var b in groupPlaces)
                                {
                                    if (b.placeid == place_id)
                                    {
                                        b.outdoorModels.Add(a);
                                        added = true;
                                        break;
                                    }
                                }
                                if (!added)
                                {
                                    List <OutdoorModel> l = new List <OutdoorModel>();
                                    l.Add(a);
                                    GooglePlaceIdModel newModel = new GooglePlaceIdModel()
                                    {
                                        placeid       = a.placeid,
                                        placeaddress  = a.placeaddress,
                                        outdoorModels = l
                                    };

                                    groupPlaces.Add(newModel);
                                }
                            }
                        }



                        int totalvisit = 0;

                        foreach (var z in groupPlaces)
                        {
                            z.outdoorModels = z.outdoorModels.OrderBy(d => d.timestamp).ToList();

                            int visit = 1;

                            int num = 0;

                            while (num < z.outdoorModels.Count)
                            {
                                DateTime previousDT = z.outdoorModels[num].timestamp;
                                DateTime thisDT;

                                if (num + 1 == z.outdoorModels.Count)
                                {
                                    thisDT = z.outdoorModels[num].timestamp;
                                }
                                else
                                {
                                    thisDT = z.outdoorModels[num + 1].timestamp;
                                }


                                TimeSpan duration = thisDT - previousDT;

                                if (duration.TotalMinutes > 20)
                                {
                                    visit++;
                                }
                                num++;
                            }

                            z.visit_count = visit;
                            totalvisit    = totalvisit + visit;
                        }
                        double mean = (double)totalvisit / groupPlaces.Count;

                        List <GooglePlaceIdModel> newGroupPlaces = new List <GooglePlaceIdModel>();

                        //filter by mean
                        foreach (var o in groupPlaces)
                        {
                            if (o.visit_count >= mean)
                            {
                                //if (o.visit_count >= 0)
                                newGroupPlaces.Add(o);
                            }
                        }
                        newGroupPlaces = newGroupPlaces.OrderByDescending(d => d.visit_count).ToList();


                        FeatureLocationList.ItemsSource = newGroupPlaces;
                        progressbar.Visibility          = Visibility.Collapsed;
                    }
                }
                catch
                {
                }
            }
        }