Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 注意:要开启定位权限
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void LocateClick(object sender, RoutedEventArgs e)
        {
            var    aMapGeolocator = new AMapGeolocator();
            LngLat myLngLat       = await aMapGeolocator.GetLngLatAsync();

            var icon = new AMapIcon {
                Location = myLngLat
            };

            baseLayer.Add(icon);
            await aMapControl.TrySetViewAsync(myLngLat, 15, 0, 0, AMapAnimationKind.Default);
        }