Beispiel #1
0
        private async void getStopsInfo()
        {
            string errorMessage = null;

            Geopoint bottomLeft = MapExtensions.GetBottomLeftCorner(mapControl);
            Geopoint topRight   = MapExtensions.GetTopRightCorner(mapControl);

            if (mapControl.ZoomLevel >= 16 &&
                (stopsLoadingFailed || lastTopRight == null || lastBottomLeft == null ||
                 bottomLeft.Position.Latitude != lastBottomLeft.Position.Latitude ||
                 bottomLeft.Position.Longitude != lastBottomLeft.Position.Longitude ||
                 topRight.Position.Latitude != lastTopRight.Position.Latitude ||
                 topRight.Position.Longitude != lastTopRight.Position.Longitude))
            {
                lastBottomLeft = bottomLeft;
                lastTopRight   = topRight;

                MapProgressBar.Visibility = Visibility.Visible;

                try
                {
                    string webresponse = await Network.StopsByViewport(bottomLeft, topRight);

                    List <Stop> rootObject = JsonConvert.DeserializeObject <List <Stop> >(webresponse);

                    CurrentStopList.Clear();

                    foreach (Stop s in rootObject)
                    {
                        CurrentStopList.Add(s);
                    }
                    LastBusStopUpdate  = DateTime.Now;
                    stopsLoadingFailed = false;
                }
                catch (Exception ex)
                {
                    errorMessage       = ex.Message;
                    stopsLoadingFailed = true;
                }

                if (errorMessage != null)
                {
                    MessageDialog msg = new MessageDialog("Houve algum problema durante a requisição ao servidor. Por favor, verifique se o aparelho está conectado à internet e tente novamente.", "Você está conectado à internet?");
                    await msg.ShowAsync();
                }

                MapProgressBar.Visibility = Visibility.Collapsed;
            }
        }