Working With Map Control - Part Two

Before reading this article, please go through the following article.

In this article, you will learn how to use Button Control, TextBlock control, and TextBox Control in Visual C# environment. Also, you will be able to develop a simple arithmetic calculation app in Universal Windows Apps development, using XAML and Visual C#. 

The following important tools are required for developing a UWP application,

  1. Windows 10 (Recommended).
  2. Visual Studio 2015 Community Edition (It is a free software available online).

Now, we can discuss the step by step App development.

If you are new to Map control component, I suggest you learn the following article.
In this article we will see about how to set a street view experience
 
Step 1: Open the already created project called "Mapsample" that is created and deployed in your machine or create a new Universal application by following the above link.
 
Step 2: Open MainPage.Xaml.cs and add the  following code as shown below for creating an Aerial.
 
Aerial 3D code is given below, 
  1. Mapsample.Style = MapStyle.Aerial3D;  
Overall code for setting aerial code is, 
  1. private async void Mapsample_Loaded(object sender, RoutedEventArgs e)  
  2.        {  
  3.                  
  4.            var center =  
  5.                new Geopoint(new BasicGeoposition()  
  6.                {  
  7.                    Latitude = 11.66509,  
  8.                    Longitude = 78.154587  
  9.   
  10.                });  
  11.   
  12.            
  13.            await Mapsample.TrySetSceneAsync(MapScene.CreateFromLocationAndRadius(center, 3000));  
  14.   
  15.            Mapsample.Center =  
  16.          new Geopoint(new BasicGeoposition()  
  17.          {  
  18.              Latitude = 11.66509,  
  19.              Longitude = 78.154587  
  20.          });  
  21.   
  22.            Mapsample.ZoomLevel = 16;  
  23.   
  24.            //check for 3D support  
  25.            if (Mapsample.Is3DSupported)  
  26.            {  
  27.                //set style to 3D  
  28.                Mapsample.Style = MapStyle.Aerial3D;  
  29.   
  30.                //create a mapscene for lat and long  
  31.                //facing East (90 deg) and pitched 45 deg  
  32.                var mapScene = MapScene.CreateFromLocationAndRadius(Mapsample.Center, 500, 90, 45);  
  33.                await Mapsample.TrySetSceneAsync(mapScene);  
  34.            }  
  35.        }  
Entire code is in Xaml.cs, 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.IO;  
  4. using System.Linq;  
  5. using System.Runtime.InteropServices.WindowsRuntime;  
  6. using Windows.Devices.Geolocation;  
  7. using Windows.Foundation;  
  8. using Windows.Foundation.Collections;  
  9. using Windows.UI.Xaml;  
  10. using Windows.UI.Xaml.Controls;  
  11. using Windows.UI.Xaml.Controls.Maps;  
  12. using Windows.UI.Xaml.Controls.Primitives;  
  13. using Windows.UI.Xaml.Data;  
  14. using Windows.UI.Xaml.Input;  
  15. using Windows.UI.Xaml.Media;  
  16. using Windows.UI.Xaml.Navigation;  
  17.   
  18. // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409  
  19.   
  20. namespace Mapsample  
  21. {  
  22.     /// <summary>  
  23.     /// An empty page that can be used on its own or navigated to within a Frame.  
  24.     /// </summary>  
  25.     public sealed partial class MainPage : Page  
  26.     {  
  27.         public MainPage()  
  28.         {  
  29.             this.InitializeComponent();  
  30.             Mapsample.Loaded += Mapsample_Loaded;  
  31.         }  
  32.   
  33.         private async void Mapsample_Loaded(object sender, RoutedEventArgs e)  
  34.         {  
  35.                   
  36.             var center =  
  37.                 new Geopoint(new BasicGeoposition()  
  38.                 {  
  39.                     Latitude = 11.66509,  
  40.                     Longitude = 78.154587  
  41.   
  42.                 });  
  43.   
  44.             
  45.             await Mapsample.TrySetSceneAsync(MapScene.CreateFromLocationAndRadius(center, 3000));  
  46.   
  47.             Mapsample.Center =  
  48.           new Geopoint(new BasicGeoposition()  
  49.           {  
  50.               Latitude = 11.66509,  
  51.               Longitude = 78.154587  
  52.           });  
  53.   
  54.             Mapsample.ZoomLevel = 16;  
  55.   
  56.             //check for 3D support  
  57.             if (Mapsample.Is3DSupported)  
  58.             {  
  59.                 //set style to 3D  
  60.                 Mapsample.Style = MapStyle.Aerial3D;  
  61.   
  62.                 //create a mapscene for lat and long  
  63.                 //facing East (90 deg) and pitched 45 deg  
  64.                 var mapScene = MapScene.CreateFromLocationAndRadius(Mapsample.Center, 500, 90, 45);  
  65.                 await Mapsample.TrySetSceneAsync(mapScene);  
  66.             }  
  67.         }  
  68.   
  69.     }  
  70.   
  71. }  
  72.      
Output 
 
 


Similar Articles