0

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

        }

    }  
}
  • Have your issue been resolved? It seems your code also can work well. Besides, you can also look into https://learn.microsoft.com/en-us/windows/uwp/maps-and-location/display-poi#add-an-image. – Breeze Liu - MSFT May 21 '18 at 08:12

1 Answers1

0

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.

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

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.

Duncan Lawler
  • 1,772
  • 8
  • 13
  • how do i create an instance for MapControl? –  May 17 '18 at 17:28
  • I tried: MapControl mapInstance = new MapControl(); ............. mapInstance.Children.Add(img); but it didnt work –  May 17 '18 at 17:37
  • The map control instance name will be whatever you set in your XAML when you declared the map control (x:Name="xxxx") or if you added the map control from code behind, whatever name you used there (note if you added it from code behind you will have to also add it to the page visual tree somewhere for it to display - creating it as you have above without adding to the visual tree will leave it invisible). – Duncan Lawler May 17 '18 at 17:54
  • This is my current xaml. I have only added the image from the code behind. should I also add it from the xaml? if so, would you mind telling me how to do it? ` ` –  May 17 '18 at 18:20
  • That all looks fine - if MapView is your instance name, that's what you should be adding the Children. Adding the image from code behind is fine - I'd check to make sure your image is loading OK as the next step, or just use MapIcon or MapBillboard instead. – Duncan Lawler May 17 '18 at 18:37
  • I'm currently using MapBillBoard. Thank You! –  May 17 '18 at 20:35