【问题标题】:UWP does not show a geoPoint-based image on the mapUWP 不在地图上显示基于 geoPoint 的图像
【发布时间】:2018-05-17 15:27:51
【问题描述】:

我正在尝试根据其地理点放置图像。但是,图像不会显示在地图上。我想确保当我们放大/缩小地图时,图像将保持原位并根据其固定坐标调整其大小。我还必须在 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);

        }

    }  
}

【问题讨论】:

标签: c# uwp geolocation uwp-maps


【解决方案1】:

您的内容看起来正确 - 您只需将其添加到地图控件实例的 .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 是合适的。

【讨论】:

  • 如何为 MapControl 创建一个实例?
  • 我试过了: MapControl mapInstance = new MapControl(); ............. mapInstance.Children.Add(img);但它没有工作
  • 地图控件实例名称将是您在声明地图控件 (x:Name="xxxx") 时在 XAML 中设置的任何名称,或者如果您从后面的代码添加地图控件,则无论您使用什么名称在那里使用(请注意,如果您从后面的代码中添加它,则还必须将其添加到页面可视化树中的某个位置才能显示 - 像上面那样创建它而不添加到可视化树将使其不可见)。
  • 这是我当前的 xaml。我只从后面的代码中添加了图像。我还应该从 xaml 添加它吗?如果是这样,你介意告诉我怎么做吗? ` `
  • 一切看起来都很好 - 如果 MapView 是您的实例名称,那么您应该添加子项。从后面的代码添加图像很好 - 我会检查以确保您的图像在下一步加载正常,或者只使用 MapIcon 或 MapBillboard。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-10
  • 1970-01-01
  • 2017-05-15
  • 2014-06-24
  • 1970-01-01
  • 2023-04-11
  • 1970-01-01
相关资源
最近更新 更多