In normal map we have only option to show the map in Satellite or Ariel view but in Windows 10 we have option to show 3D map. It’s very easy to implement 3D map in Universal App.
Now we are going to see how to create a map control to display the map normally and then set the map control to show the map in 3D. Map control with 3D helps the user to view the location at any angle.
Let’s create new Windows 10 Universal Windows app.
First enable the app capabilities “Location” to allow your app to access the location. Open “Package.appxmanifest” file and enable location like the following,
Next go to your MainPage.XAML and add the following xmlns,
- xmlns:maps="using:Windows.UI.Xaml.Controls.Maps"
Add the MapControl using the following xaml code.
- <maps:MapControl x:Name="my3dMap" Loaded="my3dMap_Loaded"></maps:MapControl>
Now go to code behind page and follow the below steps.
Firstly, check the map supports 3D.
Set the map style Aerial3DwithRoads or Aerial3D as you wish. Then set the position latitude and longitude and finally call the TrySetSceneAsync method by passing mapscene.
Here's the complete code,
- private async void my3dMap_Loaded(object sender, RoutedEventArgs e)
- {
- if (my3dMap.Is3DSupported)
- {
- my3dMap.Style = MapStyle.Aerial3DWithRoads;
- BasicGeoposition geoposition = new BasicGeoposition();
- geoposition.Latitude = 8.4875;
- geoposition.Longitude = 76.9525;
- Geopoint location = new Geopoint(geoposition);
- MapScene mapScene = MapScene.CreateFromLocationAndRadius(location, 500, 150, 70);
- await my3dMap.TrySetSceneAsync(mapScene);
- }
- }
- }
Now run the app and you can see the following output,
For Source
Code. Note:
It is showing warning message
MapServiceToken not specified, for that we need to get the token from Bing Map Development Center.