UWP不会在地图上显示基于geoPoint的图像

时间:2018-05-17 15:27:52

标签: c# uwp geolocation uwp-maps

我正在尝试根据其地理位置放置图像。但是,图像不会显示在地图上。我想确保当我们放大/缩小地图时,图像将保持原位并根据其固定坐标调整其大小。我是否还必须在xaml页面中插入图像?目前我只在cs页面上添加图片。

有人可以告诉我如何解决这个问题吗? MapView是此代码中的MapControl。

namespace HelpMe
{

    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            addImage();

        }

        //adding image
        public void addImage()
        {
            Image img = new Image();
            img.Height = 100;
            img.Width = 100;
            img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Unknown.jpg"));
            img.RenderTransform = new CompositeTransform() { Rotation = 0 };
            MapControl.SetNormalizedAnchorPoint(img, new Point(0.5, 0.5));
            MapControl.SetLocation(img, new Geopoint(new BasicGeoposition() { Latitude = 0, Longitude = 0, Altitude = 0 }));
            MapView.Children.Add(img);

        }

    }  
}

1 个答案:

答案 0 :(得分:0)

你看起来是正确的 - 你只需要将它添加到地图控件实例的.Children,而不是页面。您不需要设置渲染变换。您可能会检查您的位图资产是否正确加载,并且您选择的BasicGeoposition是您想要的位置。

    Image img = new Image();
    img.Height = 100;
    img.Width = 100;
    img.Source = new BitmapImage(new Uri("ms-appx:///Assets/YourBitmapName.jpg"));
    MapControl.SetNormalizedAnchorPoint(img, new Point(0.5, 0.5));
    MapControl.SetLocation(img, new Geopoint(new BasicGeoposition() { Latitude = 47, Longitude = -122, Altitude = 0 }, AltitudeReferenceSystem.Terrain));
    yourMapControlInstanceName.Children.Add(img);

请注意,对于像这样的简单图像,最好使用MapIcon。与固定的XAML元素相比,这将提高性能并更好地与地图移动同步。

如果您希望图像在放大/缩小时自动缩放,则MapBillboard是合适的。