如何在Windows中创建10引脚拖动给挑定位功能? [英] How to create draggable pin in windows 10 to give pick location functionality?

查看:112
本文介绍了如何在Windows中创建10引脚拖动给挑定位功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 10工作地图控件,我想允许用户拖动引脚,当用户放下脚想要得到那个位置的经度和纬度,并通过使用API​​.I添加地图获得位置的地址。图标采用以下code

I am working on MapControl in Windows 10 and I want to allow the user to drag the pin and when the user drops the pin want to get latitude and longitude of that position and get the location address by using API.I added Map Icon using following code

MapControl map = frameworkElement as MapControl;
map.MapServiceToken= "my service token";
BasicGeoposition councilPosition = new BasicGeoposition()
{
     Latitude = Convert.ToDouble(Info.GetType().GetRuntimeProperty("LATITUDE").GetValue(councilInfo, null)),
     Longitude = Convert.ToDouble(Info.GetType().GetRuntimeProperty("LONGITUDE").GetValue(councilInfo, null))
};

Geopoint pinPoint = new Geopoint(councilPosition);

MapIcon locationPin = new MapIcon();
locationPin.Image= RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Images/pushpin.png"));
locationPin.Title = councilInfo.COUNCIL_NAME;
locationPin.CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible;
locationPin.Location = councilPoint;
locationPin.NormalizedAnchorPoint = new Point(0.5, 1.0);
locationPin.ZIndex = 0;

map.MapElements.Add(locationPin);
await map.TrySetViewAsync(locationPin.Location, 15D, 0, 0, MapAnimationKind.Bow);

有人建议需要哪些事件可以用来实现接定位功能?

Can someone suggest which events are required to be used to achieve pick location functionality?

推荐答案

转寄此的链接。他们指定使用XAML显示点。相反,边框可以有网格背景图钉图片,听为电网操纵事件。

Refer this link. They have specified display points using XAML. Instead of border you can have Grid with background pushpin image,listen to manipulation events for that grid.

这里是code实现,我上面说。

here is the code to achieve what i told above.

    private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            BasicGeoposition snPosition = new BasicGeoposition() { Latitude = 47.7356039173901, Longitude = -122.310697222129

            };
            Geopoint snPoint = new Geopoint(snPosition);

            // Create a XAML border.
            Grid grid = new Grid
            {
                Width=100,
                Height=100,
                Background = new ImageBrush() {ImageSource= new BitmapImage(new Uri("ms-appx:///Assets/icon.png", UriKind.RelativeOrAbsolute)), Stretch = Stretch.UniformToFill}
            };
              grid.ManipulationMode = ManipulationModes.TranslateX|ManipulationModes.TranslateY;
 grid.ManipulationCompleted += Grid_ManipulationCompleted;
            grid.ManipulationDelta +=Grid_ManipulationDelta;
            // Center the map over the POI.
            MapControl1.Center = snPoint;
            MapControl1.ZoomLevel = 14;
            CompositeTransform tran = new CompositeTransform();
            grid.RenderTransform = tran;
            // Add XAML to the map.
            MapControl1.Children.Add(grid);
            MapControl.SetLocation(grid, snPoint);
            MapControl.SetNormalizedAnchorPoint(grid, new Point(0.5, 0.5));
        }  

        private void Grid_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
        {
            Grid grid = sender as Grid;
            CompositeTransform xform = grid.RenderTransform as CompositeTransform;


            xform.TranslateX += e.Delta.Translation.X;
            xform.TranslateY += e.Delta.Translation.Y;
         //   Rect point = grid.TransformToVisual(MapControl1).TransformBounds(new Rect(0,0, grid.Width, grid.Height));

            e.Handled = true;
          //  Geopoint gPoint;
           // MapControl1.GetLocationFromOffset(new Point(point.X, point.Y), out gPoint);
           // Debug.WriteLine(gPoint.Position.Latitude);
           // Debug.WriteLine(gPoint.Position.Longitude);
        }

  private void Grid_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
        {
            Grid grid = sender as Grid;
            Rect point = grid.TransformToVisual(MapControl1).TransformBounds(new Rect(0, 0, grid.Width, grid.Height);
            Geopoint gPoint;
            MapControl1.GetLocationFromOffset(new Point(point.X, point.Y), out gPoint);
            Debug.WriteLine(gPoint.Position.Latitude);
            Debug.WriteLine(gPoint.Position.Longitude);
        }

位置阻力后取不准确。你可以做一点R&放大器;关于如何获取accuarate点WRT,以地图控件

这篇关于如何在Windows中创建10引脚拖动给挑定位功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆