【问题标题】:Is there a way to move adjust a pushpin position manualy on windows phone 8 using bing maps?有没有办法使用 bing 地图在 windows phone 8 上手动调整图钉位置?
【发布时间】:2014-09-22 11:19:00
【问题描述】:

我正在开发一个使用 bing 地图的 windows phone 8.0 应用程序。我想用我当前的位置添加一个图钉。到目前为止太好了。我无法做到的是移动那个别针。更准确地说,我想点击那个大头针并将其移动到地图上的其他位置。

我尝试了 ManipulationStarted、ManipulationDelta、ManipulationCompleted 和网络上的其他资源等事件,但还没有结果。

我的 C# 代码:

public partial class MainPage : PhoneApplicationPage
    {
        Pushpin pin = new Pushpin();
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            GetCurrentPosition();
        }

        async void GetCurrentPosition()
        {
        Geolocator geolocator = new Geolocator();
        geolocator.DesiredAccuracyInMeters = 50; 
        Geoposition geoposition = await geolocator.GetGeopositionAsync();
        Grid MyGrid = new Grid();
        MyGrid.RowDefinitions.Add(new RowDefinition());
        MyGrid.RowDefinitions.Add(new RowDefinition());
        MyGrid.Background = new SolidColorBrush(Colors.Transparent);            

        pin.Content = "I'm a pin";
        pin.Foreground = new SolidColorBrush(Colors.Purple);
        pin.ManipulationDelta += pin_ManipulationDelta;
        pin.ManipulationStarted += pin_ManipulationStarted;
        pin.ManipulationCompleted += pin_ManipulationCompleted;

        MyGrid.Children.Add(pin);

        //Creating a MapOverlay and adding the Grid to it.
        MapOverlay MyOverlay = new MapOverlay();
        MyOverlay.Content = MyGrid;

        MyOverlay.GeoCoordinate = new GeoCoordinate(geoposition.Coordinate.Latitude, geoposition.Coordinate.Longitude);
        MyOverlay.PositionOrigin = new Point(0, 0.5);

        MyMap.Center = new System.Device.Location.GeoCoordinate(geoposition.Coordinate.Latitude, geoposition.Coordinate.Longitude);
        MyMap.ZoomLevel = 16;
        MyMap.CartographicMode = Microsoft.Phone.Maps.Controls.MapCartographicMode.Road;

        MapLayer MyLayer = new MapLayer();
        MyLayer.Add(MyOverlay);
        MyMap.Layers.Add(MyLayer);

        translateTransform = new TranslateTransform();
    }

    void pin_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e)
    {
        //MessageBox.Show("started");
    }

    void pin_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
    {
        MessageBox.Show("moving");
         //how do a get the coordonites while I'm moving the pin?
    }

    void pin_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
    {
        MessageBox.Show("completed");
    }
}

Aby 想法如何使图钉可拖动?如果我设置 pin.AllowDrop=true 它会抛出 NotImplementedException。

提前谢谢你!

【问题讨论】:

标签: c# mobile windows-phone-8 bing-maps


【解决方案1】:

只是想法有点不同......

我为NZ Topo Map 使用的解决方案是在地图上覆盖一个十字准线,这样用户就可以通过拖动地图而不是拖动大头针来精确定位大头针。然后我会使用一个带有勾号和叉号的应用栏来表示“创建图钉”和“取消”。

只是一个可供您考虑的替代 UI 想法,它可能更容易实现,也可能对用户更容易。

【讨论】:

    【解决方案2】:

    您必须在地图上的鼠标事件上设置移动事件。这将使您能够跟踪用户移动到的位置。本质上,您将向图钉添加鼠标按下事件,该事件将设置一个要捕获的标志以允许拖动图钉。然后,您将使用地图上的鼠标移动事件来重新定位图钉,并使用地图上的鼠标向上事件来关闭拖动标志。您可能还希望显示地图的平移。尝试在触发鼠标按下事件时捕获中心值,然后在打开拖动标志时在鼠标移动事件上不断地将地图的中心设置为该值。

    【讨论】:

      猜你喜欢
      • 2013-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多