1
votes

I want to add an image on my MapControl. I have tried like below. But throws an exception

System.TypeLoadException: Requested Windows Runtime type 'Windows.UI.Xaml.Controls.Maps.MapElementsLayer' is not registered.

public void AddSpaceNeedleIcon()
{
var MyLandmarks = new List<MapElement>();

BasicGeoposition snPosition = new BasicGeoposition { Latitude = 47.620, Longitude = -122.349 };
Geopoint snPoint = new Geopoint(snPosition);

var spaceNeedleIcon = new MapIcon
{
    Location = snPoint,
    NormalizedAnchorPoint = new Point(0.5, 1.0),
    ZIndex = 0,
    Title = "Space Needle"
};

MyLandmarks.Add(spaceNeedleIcon);

var LandmarksLayer = new MapElementsLayer
{
    ZIndex = 1,
    MapElements = MyLandmarks
};

myMap.Layers.Add(LandmarksLayer);

myMap.Center = snPoint;
myMap.ZoomLevel = 14;
}

My Project's target version is : Windows 10 Fall Creators Update(10.0,Build 16299) Min version : windows 10 (10.0,Build 10240)

1

1 Answers

1
votes

The MapElementsLayer class requires device family Windows 10 Fall Creators Update (introduced v10.0.16299.0), in another word, you must call this API in a windows 10 device target 16299 or higher. If your windows 10 device the app running on does't met this requirement, you may get the above exception.

There will be cases when you want to call an API in an extension SDK that you've referenced, but that API is not part of the device family you are targeting, to avoid get the above exception, you could write adaptive code with the ApiInformation class. For example, before you are using MapElementsLayer class, you could write code like follows:

bool isMapElementsLayersAPIPresent =
    Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Xaml.Controls.Maps.MapElementsLayer");

if (isMapElementsLayersAPIPresent)
{
   AddSpaceNeedleIcon();
}

More details please reference this document.