Example #1
0
        public async void InitializeCityInfo()
        {
            int  retry  = 0;
            bool failed = true;

            while (retry < 3 && failed)
            {
                //get city info base on current location
                try
                {
                    string             url     = SogoMapService.GetCityInfoURL();
                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);

                    HttpResponseMessage response = await httpClient.SendAsync(request,
                                                                              HttpCompletionOption.ResponseHeadersRead);

                    string result = "";
                    using (Stream responseStream = await response.Content.ReadAsStreamAsync())
                    {
                        int    read          = 0;
                        byte[] responseBytes = new byte[1000];
                        do
                        {
                            read = await responseStream.ReadAsync(responseBytes, 0, responseBytes.Length);

                            string tmp = System.Text.Encoding.GetEncoding("GBK").GetString(responseBytes, 0, read);
                            result += tmp;
                        }while (read != 0);
                    }
                    this.CurrentCity = SogoMapService.GetCityInfo(result);

                    this.CurrentCityName = this.CurrentCity.response.city;
                    this.cityText.Text   = this.CurrentCityName;
                    failed = false;
                }
                catch
                {
                    failed = true;
                    retry++;
                }
            }

            if (retry == 3 && failed)
            {
                var messageDialog = new MessageDialog("无法定位到城市信息,请稍后重新定位城市");
                await messageDialog.ShowAsync();
            }
        }
Example #2
0
        public async void Select_Line(string lineId)
        {
            int  retry  = 0;
            bool failed = true;

            while (retry < 3 && failed)
            {
                string err = string.Empty;
                try
                {
                    string             url     = SogoMapService.GetLineInfoURL(lineId);
                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);

                    HttpResponseMessage response = await httpClient.SendAsync(request,
                                                                              HttpCompletionOption.ResponseHeadersRead);

                    string result = "";
                    using (Stream responseStream = await response.Content.ReadAsStreamAsync())
                    {
                        int    read          = 0;
                        byte[] responseBytes = new byte[1000];
                        do
                        {
                            read = await responseStream.ReadAsync(responseBytes, 0, responseBytes.Length);

                            string tmp = System.Text.Encoding.GetEncoding("GBK").GetString(responseBytes, 0, read);
                            result += tmp;
                        }while (read != 0);
                    }

                    this.CurrentStation = SogoMapService.GetStationInfo(result);

                    /*
                     * if (CurrentStation != null)
                     * {
                     *  string points = "";
                     *  StationFeature[] features = CurrentStation.response.resultSet.busLine.stationData.StationFeatures;
                     *
                     *  for (int i = 0; i < features.Length; i++)
                     *  {
                     *      if (features[i].type.StartsWith("L"))
                     *      {
                     *          continue;
                     *      }
                     *      points += features[i].points.txt;
                     *      points += ";";
                     *  }
                     *  url = SogoMapService.GetTranslationInfoURL(points.Substring(0, points.Length - 1));
                     *  AsyncQueryData query = new AsyncQueryData();
                     *  query.url = url;
                     *  query.queryData();
                     *  result = query.result;
                     *
                     *  TranslationLocation translation = SogoMapService.GetTranslationInfo(result);
                     *
                     *  if (translation != null)
                     *  {
                     *      TranslationPoint[] translatedpoints = translation.response.points;
                     *      features = CurrentStation.response.resultSet.busLine.stationData.StationFeatures;
                     *
                     *      int step = 0;
                     *      for (int i = 0; i < features.Length; i++)
                     *      {
                     *          if (features[i].type.StartsWith("L"))
                     *          {
                     *              continue;
                     *          }
                     *          if (step < translatedpoints.Length)
                     *          {
                     *              features[i].longitude = translatedpoints[step].longitude;
                     *              features[i].latitude = translatedpoints[step].latitude;
                     *              step++;
                     *          }
                     *      }
                     *  }
                     * }* */

                    loadView(typeof(StationChoose));
                    failed = false;
                }
                catch
                {
                    failed = true;
                    retry++;
                }
            }

            if (retry == 3 && failed)
            {
                var messageDialog = new MessageDialog("搜索结果有误,请稍后重新搜索");
                await messageDialog.ShowAsync();
            }
        }
Example #3
0
        private async void SearchBtn_Click(object sender, RoutedEventArgs e)
        {
            if (this.CurrentCityName == null || this.CurrentCityName == string.Empty)
            {
                var messageDialog = new MessageDialog("请先定位城市,然后再搜索");
                await messageDialog.ShowAsync();

                return;
            }
            //Helpers.ScenarioStarted(searchBtn, cancelBtn);
            int  retry  = 0;
            bool failed = true;

            while (retry < 3 && failed)
            {
                try
                {
                    string             lineId  = this.lineTextbox.Text;
                    string             url     = SogoMapService.GetBusInfoURL(this.CurrentCityName, lineId);
                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);

                    HttpResponseMessage response = await httpClient.SendAsync(request,
                                                                              HttpCompletionOption.ResponseHeadersRead);

                    string result = "";
                    using (Stream responseStream = await response.Content.ReadAsStreamAsync())
                    {
                        int    read          = 0;
                        byte[] responseBytes = new byte[1000];
                        do
                        {
                            read = await responseStream.ReadAsync(responseBytes, 0, responseBytes.Length);

                            string tmp = System.Text.Encoding.GetEncoding("GBK").GetString(responseBytes, 0, read);
                            result += tmp;
                        }while (read != 0);
                    }

                    this.CurrentBus = SogoMapService.GetBusInfo(result);

                    if (this.CurrentBus != null && this.CurrentBus.response.busError != null)
                    {
                        failed = false;
                        var messageDialog = new MessageDialog(this.CurrentBus.response.busError.errMsg);
                        await messageDialog.ShowAsync();

                        return;
                    }
                    else if (this.CurrentBus != null)
                    {
                        failed = false;
                        loadView(typeof(BusLineChoose));
                        return;
                    }
                }
                catch
                {
                    failed = true;
                    retry++;
                }
            }

            if (retry == 3 && failed)
            {
                var messageDialog = new MessageDialog("搜索结果有误,请修改搜索值重新搜索");
                await messageDialog.ShowAsync();
            }
        }
Example #4
0
        void ageol_PositionChanged(AGeolocator sender, APositionChangedEventArgs args)
        {
            this.Dispatcher.RunAsync(CoreDispatcherPriority.High, async() =>
            {
                CurrentLocation = args.LngLat;

                try
                {
                    //update current location
                    if (this.currentViewType != null && this.currentViewType == typeof(MapView))
                    {
                        AMarker marker             = new AMarker();
                        marker.LngLat              = this.CurrentLocation;
                        marker.IconURI             = new Uri("http://api.amap.com/webapi/static/Images/marker_sprite.png ");
                        ATip tip                   = new ATip();
                        tip.Title                  = "当前位置";
                        tip.ContentText            = "Current Position";
                        marker.TipFrameworkElement = tip;
                        this.map.Children.Clear();
                        this.map.Children.Add(marker);
                        marker.OpenTip();
                    }

                    if (DateTime.Now.ToFileTime() - lastUpdate.ToFileTime() < 30000000)
                    {
                        return;
                    }

                    //convert location to sogo location
                    string points = string.Format("{0},{1}", CurrentLocation.LngX, CurrentLocation.LatY);
                    string url    = SogoMapService.GetTranslationInfoURL(points);
                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);

                    HttpResponseMessage response = await httpClient.SendAsync(request,
                                                                              HttpCompletionOption.ResponseHeadersRead);

                    string result = "";
                    using (Stream responseStream = await response.Content.ReadAsStreamAsync())
                    {
                        int read             = 0;
                        byte[] responseBytes = new byte[1000];
                        do
                        {
                            read       = await responseStream.ReadAsync(responseBytes, 0, responseBytes.Length);
                            string tmp = System.Text.Encoding.GetEncoding("GBK").GetString(responseBytes, 0, read);
                            result    += tmp;
                        }while (read != 0);
                    }

                    TranslationLocation translation = SogoMapService.GetTranslationInfo(result);
                    if (translation != null && translation.response.points.Length == 1)
                    {
                        this.CurrentSogoLongitude = translation.response.points[0].longitude;
                        this.CurrentSogoLatitude  = translation.response.points[0].latitude;
                    }
                }
                catch
                {
                }
                //check whether need alert
                this.CheckReminder();
                this.lastUpdate = DateTime.Now;
            });
        }