示例#1
0
        async void Init()
        {
            try
            {
                var info = await bookRepository.SearchBookInfo(isbn);

                Info.IsLoading = false;

                if (info == null)
                {
                    Info.BindingContext = new { Title = "本の情報が見つかりませんでした" };
                    return;
                }

                Info.BindingContext = info;

                if (!BookInfo.GetAll().ToList().Contains(info))
                {
                    info.Write();
                }

                var favoritesTask = bookRepository.SearchInFavorites(isbn, new Progress <List <SearchResult> >(list =>
                {
                    this.list.Favorites = list;
                }));

                var location = await CrossGeolocator.Current.GetLastKnownLocationAsync();

                if (location == null)
                {
                    location = await CrossGeolocator.Current.GetPositionAsync(TimeSpan.FromSeconds(5));
                }

                var locationTask = Task.Delay(1);
                if (location != null)
                {
                    locationTask = bookRepository.SearchInLocation(isbn, location.Longitude, location.Latitude, new Progress <List <SearchResult> >(list =>
                    {
                        this.list.Nearby = list;
                    }));
                }
                await Task.WhenAll(favoritesTask, locationTask);
            }
            catch (Plugin.Geolocator.Abstractions.GeolocationException ex)
            {
                await DisplayAlert("エラー", "位置情報を取得できませんでした", "了解");
            }
            catch (Exception ex)
            {
                await DisplayAlert("エラー", "データを取得できませんでした", "了解");
            }
        }