Now a days, integration of maps within an application is common and developers wants to integrate their application to use maps. So, in this post, we will create an Universal Windows Application to use Bing Maps Api and utilize Maps functionality within the application.
For creating this application, first, we will create an Universal Windows App in Visual studio. Then, we will open our XAML file of the page and add the following code for the map:
After adding the code in designer, we will add following namespaces in the .CS file of the page to use code for fetching current location of a person and showing it on the map:
Now, we will add the code for our Button Click event handler for “Get Location” Button and Selection Changed event handler for Combo box for our view:
private async void Location_Click(object sender, RoutedEventArgs e)
var accessStatus = await Geolocator.RequestAccessAsync();
Geolocator gl = new Geolocator();
Geoposition gp = await gl.GetGeopositionAsync();
Geopoint currloc = gp.Coordinate.Point;
MapControl1.Center = currloc;
MapControl1.ZoomLevel = 15;
MapIcon mi = new MapIcon();
mi.Location = myloc;
mi.NormalizedAnchorPoint = new Point(0.5, 1.0);
mi.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/pin.png")); // Add a pin to the location in Map
mi.ZIndex = 0;
private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
MapControl1.Style = MapStyle.None;
MapControl1.Style = MapStyle.Aerial;
MapControl1.Style = MapStyle.Aerial3D;
MapControl1.Style = MapStyle.Aerial3DWithRoads;
MapControl1.Style = MapStyle.AerialWithRoads;
MapControl1.Style = MapStyle.Road;
MapControl1.Style = MapStyle.Terrain;
Now, we have written the code to fetch the current location of a person and show it in the map. Add pin.png to the Assets folder of the solution to show the pin on the current location on the map.
After we are done with our application in Visual Studio, we will be creating an app on Bings Map Portal which will give us the Api Key to use for fetching map from Bing Maps site.
Now, the steps to create a key for on Bing Maps Portal are:
Go to www.bingmapsportal.com -> Sign In (with outlook account) -> My Accounts -> Create or View keys -> Click here to Create new Key -> Enter Application Name which you created in Visual Studio (Use exact name as in Visual Studio) -> Select Application Type -> Create
Now, copy the key and paste it in MapServiceToken property of the MapControl control on the XAML file of the page.
Run the application and enjoy!