private int Stops_Near_ButtonClicks = 0; // счётчик кликов для перехода на страницу AR private void Stops_Near(object sender, EventArgs e) { // переход на страницу виртуальной реальности Stops_Near_ButtonClicks++; if (Stops_Near_ButtonClicks >= 3) { Stops_Near_ButtonClicks = 0; Stops_AR(null, null); } Stops_Search_Result.ItemsSource = new List <Stops.Model_XAML>(); Util.Hide(Stops_Search_NoResults); Util.Show(Stops_Root); ProgressIndicator pi = new ProgressIndicator(); pi.IsVisible = true; pi.IsIndeterminate = true; pi.Text = "Ищу ближайшие остановки..."; SystemTray.SetProgressIndicator(this, pi); try // определение местоположения { GeoCoordinate currentPosition = ARDisplay.Location; // загрузка данных var client = new WebClient(); client.Headers["If-Modified-Since"] = DateTimeOffset.Now.ToString(); // отключение кэширования client.DownloadStringCompleted += (sender2, e2) => { HtmlDocument htmlDocument = new HtmlDocument(); try { htmlDocument.LoadHtml(e2.Result); string json = htmlDocument.DocumentNode.InnerText; json = Regex.Replace(json, "[«»]", "\""); Stops.Model_Near[] b = JsonConvert.DeserializeObject <Stops.Model_Near[]>(json); Util.Show(Stops_Search_Result); Util.Hide(Stops_Search_NoResults); Util.Hide(Stops_Root); List <Stops.Model_XAML> list = new List <Stops.Model_XAML>(); Stops.Model_XAML_Comparer mc = new Stops.Model_XAML_Comparer(); foreach (Stops.Model_Near a in b) { string name = Util.TypographString(a.Name); string all = a.Id + "|" + a.Lon + "|" + a.Lat + "|" + Util.TypographString(a.Name); Stops.Model_XAML c = new Stops.Model_XAML() { Name = name, All = all }; if (!list.Contains(c, mc)) { list.Add(c); } } Stops_Search_Result.ItemsSource = list; pi.IsVisible = false; } catch { pi.IsVisible = false; MessageBox.Show("Скорее всего, нет доступа к сети. Проверь его и попробуй ещё раз.", "Ошибочка!", MessageBoxButton.OK); } }; client.DownloadStringAsync(new Uri("http://t.bus55.ru/index.php/app/get_stations_geoloc_json/" + Regex.Replace(currentPosition.Latitude.ToString(), ",", ".") + "/" + Regex.Replace(currentPosition.Longitude.ToString(), ",", "."))); } #pragma warning disable CS0168 // The variable 'e3' is declared but never used catch (Exception e3) #pragma warning restore CS0168 // The variable 'e3' is declared but never used { MessageBoxResult mbr = MessageBox.Show("Не могу найти ближайшие остановки, так как отключено определение местоположения.\nОткрыть настройки, чтобы включить его?", "Местоположение", MessageBoxButton.OKCancel); if (mbr == MessageBoxResult.OK) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. Launcher.LaunchUriAsync(new Uri("ms-settings-location:")); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. } } }
private async Task Stops_Init() { string[] b = await IO.Get("Stops"); List <Stops.Model_XAML> StopsList = new List <Stops.Model_XAML>(); if (b != null) { Util.Hide(Stops_Error); foreach (string a in b) { try { string[] line = a.Split(new Char[] { '|' }); string id = line[0]; string lon = line[1]; string lat = line[2]; string name = Util.TypographString(line[3]); StopsList.Add(new Stops.Model_XAML() { Name = name, All = id + "|" + lon + "|" + lat + "|" + name }); } catch { } } Util.Hide(Stops_Load); StopsList = StopsList.OrderBy(x => x.Name).ToList(); // OrderBy — сортировка по алфавиту //Stops_Root.ItemsSource = StopsList; // ушло в catch у ближайших остановок } else { Util.Show(Stops_Error); Util.Hide(Stops_Load); await Stops_Init(); } // дубляция (прямо как на странице карты), но мне похуй (прямо как на странице карты) try // определение местоположения { GeoCoordinate currentPosition = ARDisplay.Location; // загрузка данных var client = new WebClient(); client.Headers["If-Modified-Since"] = DateTimeOffset.Now.ToString(); // отключение кэширования client.DownloadStringCompleted += (sender2, e2) => { HtmlDocument htmlDocument = new HtmlDocument(); try { htmlDocument.LoadHtml(e2.Result); string json = htmlDocument.DocumentNode.InnerText; json = Regex.Replace(json, "[«»]", "\""); Stops.Model_Near[] с = JsonConvert.DeserializeObject <Stops.Model_Near[]>(json); List <Stops.Model_XAML> list = new List <Stops.Model_XAML>(); Stops.Model_XAML_Comparer mc = new Stops.Model_XAML_Comparer(); foreach (Stops.Model_Near a in с) { string name = Util.TypographString(a.Name); string all = a.Id + "|" + a.Lon + "|" + a.Lat + "|" + Util.TypographString(a.Name); Stops.Model_XAML c = new Stops.Model_XAML() { Name = name, All = all }; if (!list.Contains(c, mc)) { list.Add(c); } } StopsList.InsertRange(0, list); Stops_Root.ItemsSource = StopsList; } catch { Stops_Root.ItemsSource = StopsList; } }; client.DownloadStringAsync(new Uri("http://t.bus55.ru/index.php/app/get_stations_geoloc_json/" + Regex.Replace(currentPosition.Latitude.ToString(), ",", ".") + "/" + Regex.Replace(currentPosition.Longitude.ToString(), ",", "."))); } #pragma warning disable CS0168 // The variable 'e3' is declared but never used catch (Exception e3) #pragma warning restore CS0168 // The variable 'e3' is declared but never used { Stops_Root.ItemsSource = StopsList; } }