Exemple #1
0
        void map_MapLoaded(object sender, RoutedEventArgs e)
        {
            ///适用于高德地图的定位接口
            AGeolocator ageol = new AGeolocator();

            ageol.PositionChanged += ageol_PositionChanged;
        }
 void ageol_PositionChanged(AGeolocator sender, APositionChangedEventArgs args)
 {
     this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
     {
         if (!map.Children.Contains(marker))
         {
             marker.LngLat = new ALngLat(113.38563, 23.05810);
             map.Children.Add(marker); 
         }
         else
         {
             marker.LngLat = new ALngLat(113.38563, 23.05810);
         }
         map.SetZoomAndCenter(20, marker.LngLat);
         Debug.WriteLine("定位精度:" + args.Accuracy);//单位米
     });
 }
Exemple #3
0
 void ageol_PositionChanged(AGeolocator sender, APositionChangedEventArgs args)
 {
     this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
     {
         if (!map.Children.Contains(marker))
         {
             marker.LngLat = args.LngLat;
             map.Children.Add(marker);
         }
         else
         {
             marker.LngLat = args.LngLat;
         }
         map.SetZoomAndCenter(15, args.LngLat);
         Debug.WriteLine("定位精度:" + args.Accuracy);//单位米
     });
 }
        public MainPage()
        {
            this.InitializeComponent();
            _windowBounds = Window.Current.Bounds;
            // This is a static public property that will allow downstream pages to get
            // a handle to the MainPage instance in order to call methods that are in this class.
            Current                = this;
            HiddenFrame            = new Windows.UI.Xaml.Controls.Frame();
            HiddenFrame.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            ContentRoot.Children.Add(HiddenFrame);

            SettingsPane.GetForCurrentView().CommandsRequested += SettingCharmManager_CommandsRequested;

            map   = new AMap();
            ageol = new AGeolocator();
            ageol.PositionChanged += ageol_PositionChanged;

            CurrentLocation = new ALngLat(121.5, 31);
            map.Center      = CurrentLocation;

            this.SetBusName("");
            this.SetStatus("");
            lastUpdate = DateTime.Now;
        }
 void map_MapLoaded(object sender, RoutedEventArgs e)
 {
     ///适用于高德地图的定位接口
     AGeolocator ageol = new AGeolocator();
     ageol.PositionChanged += ageol_PositionChanged;
 }
Exemple #6
0
        void ageol_PositionChanged(AGeolocator sender, APositionChangedEventArgs args)
        {
            pick = true;//确定marker已选
            //map.Children.Add(marker); 
            this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {
                //第一次定位
                if (!map.Children.Contains(marker))
                {
                    marker.LngLat = args.LngLat;   //点标注的经纬度为当前定位获取的经纬度
                    map.Children.Add(marker); //将点标注添加到地图上
                }
                //位置改变时的定位
                else
                {
                    marker.LngLat = args.LngLat;
                }
                map.SetZoomAndCenter(15, args.LngLat);

                Debug.WriteLine("定位精度:" + args.Accuracy);//单位米
            });
        }
Exemple #7
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            AGeolocator ageol = new AGeolocator();    //初始化一个AGeolocator对象
            //设置位置改变监听器,调用ageol_PositionChanged 函数  
            ageol.PositionChanged += ageol_PositionChanged;  

        }
Exemple #8
0
 private async System.Threading.Tasks.Task locateme()
 {
     AGeolocator ageol = new AGeolocator();    //初始化一个AGeolocator对象
     //设置位置改变监听器,调用ageol_PositionChanged 函数  
     ageol.PositionChanged += ageol_PositionChanged;  
 }
        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;
            });
        }