Windows Phone 8 Map

In this chapter we will see how to use a map in Windows Phone 8 applications. In Windows Phone we have the map API to develop map-based applications and also the location service.

Let us see the procedure to display maps in Windows Phone 8 applications. Open the Visual Studio 2012 or 2013 IDE and create a new Windows Phone project with a proper name. Once the project is created we can see the Visual Studio IDE with the project as shown in the screen below.

map Demo

Add the Map control directly using the Map control available in the tool box as shown as in the following, this control will add the maps on running the application to manage the open the maps in the default view.

map option in tool box

Once the map control is added our screen looks as in the following.

map control

XAML Code

  1. <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">  
  2. <maps:Map x:Name="mymap1" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="587" Width="446"/>  
  3. </Grid>  
The important thing is you need to enable map capabilities to access a map in Windows Phone 8. To enable map capabilities open the WMAppManifest.xml file in your application and enable the ID_CAP_MAP as shown in the following.

enable ID_CAP_MAP

Let as navigate to a specific location in the map. We need to use the GeoCoordinate class to input the Latitude and Longitude parameters and assign it to the map as shown in the code below.

C# Code
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Net;  
  5. using System.Windows;  
  6. using System.Windows.Controls;  
  7. using System.Windows.Navigation;  
  8. using Microsoft.Phone.Controls;  
  9. using Microsoft.Phone.Shell;  
  10. using MapDemo.Resources;  
  11.   
  12. namespace MapDemo  
  13. {  
  14.     public partial class MainPage : PhoneApplicationPage  
  15.     {  
  16.         // Constructor  
  17.         public MainPage()  
  18.         {  
  19.             InitializeComponent();  
  20.             mymap1.Center = new System.Device.Location.GeoCoordinate(13.0833,80.7800);  
  21.               
  22.         }  
  23.     }  
  24.  }  
Now run your application by pressing F5 or the Execute button in the IDE and we can see the output as shown in the following.

Windows Phone 8 Map

 

Up Next
    Ebook Download
    View all
    Learn
    View all