Example #1
0
 void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         if (!AppConfig.IsOpenGeo)
         {
             MessageBoxResult msgResult = MessageBox.Show("是否开启定位", "运行定位", MessageBoxButton.OKCancel);
             if (msgResult.Equals(MessageBoxResult.OK))
             {
                 AppConfig.IsOpenGeo = true;//不再提示
                 geo = new AMapGeolocator();
                 geo.DesiredAccuracy = Windows.Devices.Geolocation.PositionAccuracy.High;
                 geo.Start();
                 geo.PositionChanged += geo_PositionChanged;
             }
             else
             {
                 return;
             }
         }
         else
         {
             geo = new AMapGeolocator();
             geo.DesiredAccuracy = Windows.Devices.Geolocation.PositionAccuracy.High;
             geo.Start();
             geo.PositionChanged += geo_PositionChanged;
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("MainPage_Loaded:" + ex.Message);
     }
 }
        private async void TrackLocationClick(object sender, RoutedEventArgs e)
        {
            MessageDialog messageDialog = new MessageDialog("启动tracking");
            await messageDialog.ShowAsync();

            trackingGeolocator = new AMapGeolocator();
            trackingGeolocator.PositionChanged += aMapGeolocator_PositionChanged;

            //模拟器不能获取经纬度
            var currentLocation = await trackingGeolocator.GetLngLatAsync();

            if (trackingIcon == null)
            {
                trackingIcon = new AMapIcon
                {
                    Image =
                        RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/marker_gps_no_sharing.png",
                                                                          UriKind.RelativeOrAbsolute)),
                    Location = currentLocation,
                    NormalizedAnchorPoint = new Point(0.5, 0.5)
                };
            }

            if (amapcircle == null)
            {
                amapcircle = new AMapCircle
                {
                    FillColor       = Color.FromArgb(80, 100, 150, 255),
                    StrokeThickness = 2,
                    StrokeColor     = Color.FromArgb(80, 0, 0, 255),
                    Center          = currentLocation,
                    Radius          = 500
                };
            }

            bool circleContained       = baseLayer.OverLays.Contains(amapcircle);
            bool trackingIconContained = baseLayer.OverLays.Contains(trackingIcon);

            if (!trackingIconContained)
            {
                baseLayer.Add(trackingIcon);
            }


            if (!circleContained)
            {
                baseLayer.Add(amapcircle);
            }


            aMapControl.TrySetViewAsync(currentLocation, 15, null, null, AMapAnimationKind.Default);
            trackingGeolocator.Start();
        }
        private async void OnMapLoaded(object sender, RoutedEventArgs e)
        {
            //TODO
            //AddMarker();


            //定位
            geolocator = new AMapGeolocator();
            geolocator.Start();//开启定位
            geolocator.PositionChanged += OnPositionChanged;

            //var location = await geolocator.GetGeopositionAsync();
            //Debug.WriteLine("CurrentLocation:{0}", location.CivicAddress);
        }
Example #4
0
        private void Mylocation_Loaded(object sender, RoutedEventArgs e)
        {
            //设置定位为高精度定位,更新间隔为0.1s,
            _mylocation = new AMapGeolocator(PositionAccuracy.High, 1, 100);
            _mylocation.Start();
            if (_isNew)
            {
                //定位用户位置,屏蔽大北京
                IAsyncOperation<Geoposition> getCurrentPosition = _mylocation.GetGeopositionAsync(new TimeSpan(1), new TimeSpan(3000));
                getCurrentPosition.Completed += GetCurrentPosition;
                _isNew = false;
            }
            
            //触发位置改变事件
            _mylocation.PositionChanged += mylocation_PositionChanged;
            

        }
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            BindHistoryData();

            m_mylocation = new AMapGeolocator();
            m_mylocation.Start();
            //触发位置改变事件
            m_mylocation.PositionChanged += mylocation_PositionChanged;
        }
Example #6
0
        /// <summary>
        /// 定位按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLoaction_Click(object sender, RoutedEventArgs e)
        {
            //TODO:重新定位后的操作,定位+搜索,应该需要删除之前的点
            try
            {
                mapToiletLayer.Children.Clear();
                mapWalkingLayer.Children.Clear();

                if (!AppConfig.IsOpenGeo)
                {
                    MessageBoxResult msgResult = MessageBox.Show("是否开启定位", "运行定位", MessageBoxButton.OKCancel);
                    if (msgResult.Equals(MessageBoxResult.OK))
                    {
                        AppConfig.IsOpenGeo = true;//不再提示

                        geo = new AMapGeolocator();
                        geo.DesiredAccuracy = Windows.Devices.Geolocation.PositionAccuracy.High;
                        geo.Start();
                        geo.PositionChanged += geo_PositionChanged;
                    }
                }
                else
                {
                    geo = new AMapGeolocator();
                    geo.DesiredAccuracy = Windows.Devices.Geolocation.PositionAccuracy.High;
                    geo.Start();
                    geo.PositionChanged += geo_PositionChanged;
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }