Adding Map Directions Task In Windows Phone 8


This article explains the Maps Directions Task. We will see how to integrate the route info and navigation in our app using the Windows Navigation app. For that purpose we will use a Windows Phone task launcher. The good thing about this launcher is it's very simple to use and can be integrated into an app with just 4-5 lines of code. So let's start.

Maps Directions Task

This is a kind of launcher provided by Windows Phone to launch mobile navigation apps. This task expects two parameters to be set and on the basis of those parameters users can use navigation services from the app itself. 

Before using this task we need to include the following namespace:

using Microsoft.Phone.Tasks;

This task has the following properties that we can use:

  • Start
    Sets the starting location for which driving directions are to be displayed.
  • End
    Sets the ending location for which driving directions are to be displayed.

To use this task we need to set the preceding two properties properly. The start and end properties use a labeled map location type value.

Labeled Map Location

It is a class that represents a location coordinate with label. Label can be a place or business name and location is defined in terms of various geo coordinates.

Properties that we need to use from this class for Maps Direction Task are as follows:

  • Label
    Sets the text label that identifies the associated geographical location. It can be business name, place or venue name.
  • Location
    Sets the geographical location associated with labeled map location.  


Let's see how to use it on a contact us page of our app. Here our app page will help the user to drive to our office from its location.











    FontFamily="{StaticResource PhoneFontFamilyNormal}"

    FontSize="{StaticResource PhoneFontSizeNormal}"

    Foreground="{StaticResource PhoneForegroundBrush}"

    SupportedOrientations="Portrait" Orientation="Portrait"



    <!--LayoutRoot is the root grid where all page content is placed-->

    <Grid x:Name="LayoutRoot" Background="Transparent">


            <RowDefinition Height="Auto"/>

            <RowDefinition Height="*"/>



        <!--TitlePanel contains the name of the application and page title-->

        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">

            <TextBlock Text="Demo" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>

            <TextBlock  Text="Demo" Margin="9,-7,0,0" FontSize="40" />



        <!--ContentPanel - place additional content here-->

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

            <StackPanel Orientation="Vertical">

                <TextBlock Text="Contact US" FontSize="45" Height="106"></TextBlock>

                <TextBlock Text="Some Address Goes Here" FontSize="30" Height="106"></TextBlock>

                <Button Name="sendBtn" Click="sendBtn_Click"  Content="View Route" HorizontalAlignment="Left" Width="186" Height="80" VerticalAlignment="Bottom" Margin="132,0,0,0"/>





C# Code Behind

using Microsoft.Phone.Controls;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Diagnostics;

using Microsoft.Phone.Tasks;

using System.Windows.Media;


namespace Demo


    public partial class MainPage : PhoneApplicationPage


        // Constructor

        public MainPage()





        private void sendBtn_Click(object sender, RoutedEventArgs e)


            /* Step 1 */

            Microsoft.Phone.Tasks.MapsDirectionsTask mdt = new MapsDirectionsTask();

            /* Step 2 */

            LabeledMapLocation LMLD = new LabeledMapLocation();

            LMLD.Label = "taj mahal";

            LMLD.Location = new System.Device.Location.GeoCoordinate(27.173147600000000000, 78.042068500000030000);

            mdt.End = LMLD;

//            mdt.Start  Leave it to default, i.e to user current location.

            /* Step 3 */





The Show method is used to launch the task.






Up Next
    Ebook Download
    View all
    View all