如何使用bing Maps在Windows Store应用中实现多个新推杆的方法



我正在使用C#制作Windows Store应用程序,并且需要对绘制地图上的按PUSHPIN进行点击时的方法。到目前为止,我创建了一个名为CurrentPin的Pushpin,我在XAML代码中创建了一个名为CurrentPin。我还为这里的点击事件进行了参考,称为pushpin_tapped。

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <bm:Map x:Name="MyMap" Credentials="{StaticResource BingMapsApiKey}" Holding="map_Held">
            <bm:Map.Children>
                <bm:Pushpin x:Name="pin" Tapped="pushpinTapped">
                </bm:Pushpin>
            </bm:Map.Children>
        </bm:Map>
    </Grid>
然后,

i然后将CurrentPin放在我当前位置的onnavigatedto方法中,在mainpage.xaml.cs代码中。我还创建了何时挖掘此推动物的方法。在此方法中,我显示了一个对话框,用于何时点击CurrentPin。

private async void pushpinTapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
            {
                var x = MapLayer.GetPosition(pin);
                MessageDialog dialog = new MessageDialog("You are here " + x.Latitude + " " + x.Longitude);
                await dialog.ShowAsync();
            }

i然后有一种方法,该方法将新的推动物放在用户保存地图时,代码下面的位置:

private void map_Held(object sender, HoldingRoutedEventArgs e)        
{            
    Debug.WriteLine("You held at" + DateTime.Now.ToString() + "" + e.GetPosition(MyMap));            
    var pos = e.GetPosition(MyMap);            
    Location location;            
    MyMap.TryPixelToLocation(pos, out location);                          
    Pushpin pin = new Pushpin();            
    MyMap.Children.Add(pin);                        
    MapLayer.SetPosition(pin, location);                       
}

我知道这可能是盯着我的脸,但是当这些新销点被敲击时,我对如何获取消息框或对话框或任何事情发生。有人可以放光吗?谢谢,aimee

private void map_Held(object sender, HoldingRoutedEventArgs e)        
{            
    Debug.WriteLine("You held at" + DateTime.Now.ToString() + "" + e.GetPosition(MyMap));            
    var pos = e.GetPosition(MyMap);            
    Location location;            
    MyMap.TryPixelToLocation(pos, out location);                          
    Pushpin pin = new Pushpin();
    pin.Tapped += pushpinTapped;  // <<<<<<=====LOOK AT THIS
    MyMap.Children.Add(pin);                        
    MapLayer.SetPosition(pin, location);                       
}

在map_held中,添加用于点击事件的处理程序...

private void map_Held(object sender, HoldingRoutedEventArgs e)        
{            
    Debug.WriteLine("You held at" + DateTime.Now.ToString() + "" + e.GetPosition(MyMap));            
    var pos = e.GetPosition(MyMap);            
    Location location;            
    MyMap.TryPixelToLocation(pos, out location);                          
    Pushpin newpin = new Pushpin();            
    newpin.Tapped += pushpin_Tapped;
    MyMap.Children.Add(newpin);                        
    MapLayer.SetPosition(newpin, location);                       
}

和在您的点击事件处理程序中,将对您的PIN的引用从pin更改为以下。

private async void pushpinTapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
    PushPin tappedpin = sender as PushPin;  // gets the pin that was tapped
    if(null == tappedpin) return;           // null check to prevent bad stuff if it wasn't a pin.
    var x = MapLayer.GetPosition(tappedpin);
    MessageDialog dialog = new MessageDialog("You are here " + x.Latitude + " " + x.Longitude);
    await dialog.ShowAsync();
}

相关内容

  • 没有找到相关文章

最新更新