2014-02-06 46 views
0

在我的Windows商店應用,使用im一個bings地圖,和IM嘗試添加一個圖釘與圖像 這樣做,即時通訊做這段代碼圖釘的設置位置 - BingMaps

  Bing.Maps.Location center = new Bing.Maps.Location(); 
     center.Latitude = 40.130066068147585; 
     center.Longitude = -8.338623046875; 
     Map.Center = center; 
     Map.ZoomLevel = 12D; 

     var pushpinLayer = new MapLayer(); 
     pushpinLayer.Name = "PushPinLayer"; 
     Map.Children.Add(pushpinLayer); 

     var location = new Location(40.130066068147585D, -8.338623046875D); 
     Image pinImage = new Image(); 
     BitmapImage bitmapImage = new BitmapImage(); 
     bitmapImage.UriSource = new Uri("ms-appx:///Assets/[email protected]", UriKind.RelativeOrAbsolute); 
     pinImage.Width = 20; 
     pinImage.Height = 30; 
     pinImage.Source = bitmapImage; 

     pushpinLayer.Children.Add(pinImage); 

它添加圖釘圖像,但它出現在地圖的左上角,我不知道如何設置其位置以使用localtion變量:\

回答

2

好吧,讓您的事情有點不合適。第一部分是正確的:

Bing.Maps.Location center = new Bing.Maps.Location(); 
    center.Latitude = 40.130066068147585; 
    center.Longitude = -8.338623046875; 
    Map.Center = center; 
    Map.ZoomLevel = 12D; 

下,而不是創建一個maplayer你,而不是創造圖釘圖片:

Image pinImage = new Image(); 
    BitmapImage bitmapImage = new BitmapImage(); 
    bitmapImage.UriSource = new Uri("ms-appx:///Assets/[email protected]", UriKind.RelativeOrAbsolute); 
    pinImage.Width = 20; 
    pinImage.Height = 30; 
    pinImage.Source = bitmapImage; 

然後你就可以創建你的位置:

var location = new Location(40.130066068147585D, -8.338623046875D); 

這裏是不同的地方。您不需要創建MapLayer類的實例,而是分配元素(您的案例中的圖像)和位置 - 然後將其添加到地圖。

MapLayer.SetPosition(pinImage, location); 
Map.Children.Add(pinImage); 
+0

Ahhhh,好吧,現在我明白了,這是有道理的,謝謝:) – Ric