1

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)

user2431727
  • 877
  • 2
  • 15
  • 46

1 Answers1

1

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.

Sunteen Wu
  • 10,509
  • 1
  • 10
  • 21
  • isMapElementsLayersAPIPresent is get as false in my win10 device. Then how can I achieve it for target lower than 16299 ? My aim is to move a car on map – user2431727 Jul 23 '18 at 03:49
  • 1
    I ever created a demo for animating a pin on map may help you. You could try reference [here](https://github.com/sunteenwu/PersonalDemo/tree/master/CAnimationMap). Since on this thread, I focused on resolving your exception, for your detail requirements you may open a new thread. – Sunteen Wu Jul 24 '18 at 07:51
  • I have opened a new thread on below link. https://stackoverflow.com/questions/51518355/rotate-vehicle-pin-on-mapcontrol-according-to-the-path-uwp-c-sharp – user2431727 Jul 25 '18 at 12:01
  • can I rotate the car image according to the route it goes? now car is facing left as it is. – user2431727 Jul 26 '18 at 10:55