C# 设置图钉的位置-地图

C# 设置图钉的位置-地图,c#,xaml,windows-store-apps,bing-maps,C#,Xaml,Windows Store Apps,Bing Maps,在我的windows应用商店应用程序中,我正在使用bings地图,我正在尝试添加带有图像的图钉 为此,我正在编写这段代码 Bing.Maps.Location center = new Bing.Maps.Location(); center.Latitude = 40.130066068147585; center.Longitude = -8.338623046875; Map.Center = center;

在我的windows应用商店应用程序中,我正在使用bings地图,我正在尝试添加带有图像的图钉 为此,我正在编写这段代码

            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);

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

好的,所以你只是有点不正常。第一部分是正确的:

    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);