2012-10-17 63 views
1

我使用C#創建使用bing地圖的Windows商店應用程序。我想存儲和在地圖上檢索隨機放置圖釘的位置,但是當我使用pushpin.Location對要打印的位置,例如,我得到以下錯誤:pushpin.Location地圖錯誤的Bing地圖上的Windows商店應用程序

'Bing.Maps.Pushpin' does not contain a definition for 'Location' and no extension method 'Location' accepting a first argument of type 'Bing.Maps.Pushpin' could be found (are you missing a using directive or an assembly reference?)

簡單的代碼示例下面說明我的意思有點更清楚:

private async void pushpinTapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) 
{ 
     MessageDialog dialog = new MessageDialog("You are here" + pushPin.Location()); 
     await dialog.ShowAsync(); 
} 

它明確指出該位置是圖釘類的API here 還有這樣的例子被用於Windows Phone 7的,就像this question在屬性。

任何想法我失蹤?或者此功能不適用於Windows 8?

回答

1

它是這樣工作:

async void pin_Tapped(object sender, TappedRoutedEventArgs e) 
     { 
      Pushpin pin = sender as Pushpin; 
      Location pinLocation = MapLayer.GetPosition(pin); 
      MessageDialog dialog = new MessageDialog("You are here: " + pinLocation.Latitude +", " + pinLocation.Longitude); 
      await dialog.ShowAsync(); 
     } 
0

該多好啊一個謝謝。 我發現了另一種方法。基本上是一樣的東西,但使用var x而不是位置。

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

很酷。在運行時,var將被解析爲Location。這是一樣的,沒有傷害。 – Typist

相關問題