示例#1
0
        public async Task <bool> GetConvenientCaresAsync()
        {
            if (IsBusy)
            {
                return(false);
            }

            IsBusy    = true;
            IsNotBusy = false;

            try
            {
                if (!CrossConnectivity.Current.IsConnected)
                {
                    await page.DisplayAlert(LocaleConstants.CONNECTION_OFFLINE_TITLE,
                                            LocaleConstants.CONNECTION_OFFLINE_MESSAGE,
                                            LocaleConstants.ALERT_OK);

                    return(false);
                }

                ConvenientCares.Clear();
                OrderedConvenientCares.Clear();

                var items = await GetConvenientCaresDataAsync_debug();                 //instead of service call

                foreach (var item in items)
                {
                    item.DistanceFromLocation = MapHelper.CalculateDistance(item.Latitude, item.Longitude, Latitude, Longitude, 'M');
                    ConvenientCares.Add(item);
                }

                var orderedCC = ConvenientCares.OrderBy(l => l.DistanceFromLocation);

                foreach (var orderedItem in orderedCC)
                {
                    OrderedConvenientCares.Add(orderedItem);
                }

                return(true);
            }
            catch (Exception ex)
            {
                //await page.DisplayAlert(LocaleConstants.ISSUE_TITLE,
                //	string.Format(LocaleConstants.ISSUE_MESSAGE_FORMAT, "load convenient care locations"),
                //	LocaleConstants.ALERT_OK);

                await page.DisplayAlert("Error", ex.ToString(), "Ok");

                //catch and log to the insights
                //Xamarin.Insights.Report(ex);
            }
            finally
            {
                IsBusy    = false;
                IsNotBusy = true;
            }

            return(false);
        }
示例#2
0
        public void CalculateDistance()
        {
            foreach (var item in ConvenientCares)
            {
                item.DistanceFromLocation = MapHelper.CalculateDistance(item.Latitude, item.Longitude, Latitude, Longitude, 'M');
            }

            OrderedConvenientCares.Clear();
            foreach (var orderedItem in ConvenientCares.OrderBy(l => l.DistanceFromLocation))
            {
                OrderedConvenientCares.Add(orderedItem);
            }
        }