I'm trying to put an image according to its geopoints. However, the image does not show up on the map. I want to make sure that when we zoom in/out the map, the image will stay in place and adjust its size based on its fixed coordinate. Do i have to insert the image in the xaml page also? Currently I'm only adding image on the cs page.
can someone tell me how to fix this? MapView is MapControl in this code.
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);
}
}
}
What you have looks correct - you just need to add it to the .Children of the map control instance, not the page. You don't need to set a render transform. You might check that your bitmap asset is loading correctly and the BasicGeoposition you've chosen is where you want it.
Note that for a simple image like this it's better to use a MapIcon. This will be higher performance and synchronize better with map movement than pinned XAML elements.
If you want an image to automatically scale as you zoom in/out, a MapBillboard is appropriate.