设置图钉的位置 - BingMaps

时间:2014-02-06 17:19:16

标签: c# xaml windows-store-apps bing-maps

在我的Windows商店应用程序上,即时通讯使用绑定地图,我试图添加带图像的图钉 这样做,我正在做这段代码

            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/POI_Red_Ipad@2x.png", UriKind.RelativeOrAbsolute);
        pinImage.Width = 20;
        pinImage.Height = 30;
        pinImage.Source = bitmapImage;

        pushpinLayer.Children.Add(pinImage);

它添加了图钉图像,但它出现在地图的左上角,我不知道如何设置其位置以使用localtion变量:\

1 个答案:

答案 0 :(得分: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/POI_Red_Ipad@2x.png",   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);