Esempio n. 1
0
        public static TranslationLocation GetTranslationInfo(string result)
        {
            TranslationLocation translation = null;

            try
            {
                translation = JSON.parse <TranslationLocation>(result);
            }
            catch (Exception)
            {
            }

            return(translation);
        }
Esempio n. 2
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;
            });
        }