How to use the Maps directions task for Windows Phone 8

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

The Maps directions task launches the Maps application and displays driving directions between two points. You can specify both the start and end points, or specify only one; in the latter case, the user’s current location is used for the other one. The start and end points contain a string label, and geographic coordinates specifying the latitude and longitude of the location. If you omit the geographic coordinates, the label string is used by the Maps application as a search term.

By using Launchers, you help provide a consistent user experience throughout the Windows Phone platform. For more information, see Launchers and Choosers for Windows Phone 8.

Important Note:

The Maps application will not be launched if the device is in a location where it is not supported. Instead, a dialog is displayed to the user indicating that Maps is unavailable in their location.

To use the Maps directions task

  1. Add a reference to the System.Device assembly to your project.

  2. Add the following statements to your code.

    Imports Microsoft.Phone.Tasks
    
    using Microsoft.Phone.Tasks;
    
    Imports System.Device.Location
    
    using System.Device.Location;
    
  3. Add the following code to your application wherever you need it, such as in a button click event. To test this procedure, you can put the code in the page constructor. This is the code to launch the task.

            Dim mapsDirectionsTask As MapsDirectionsTask = New MapsDirectionsTask()
    
            ' You can specify a label and a geocoordinate for the end point.
            ' GeoCoordinate spaceNeedleLocation = new GeoCoordinate(47.6204,-122.3493);
            ' LabeledMapLocation spaceNeedleLML = new LabeledMapLocation("Space Needle", spaceNeedleLocation);
    
            ' If you set the geocoordinate parameter to null, the label parameter is used as a search term.
            Dim spaceNeedleLML As LabeledMapLocation = New LabeledMapLocation("Space Needle", Nothing)
    
            mapsDirectionsTask.End = spaceNeedleLML
    
            ' If mapsDirectionsTask.Start is not set, the user's current location is used as the start point.
    
            mapsDirectionsTask.Show()
    
    
                MapsDirectionsTask mapsDirectionsTask = new MapsDirectionsTask();
    
                // You can specify a label and a geocoordinate for the end point.
                // GeoCoordinate spaceNeedleLocation = new GeoCoordinate(47.6204,-122.3493);
                // LabeledMapLocation spaceNeedleLML = new LabeledMapLocation("Space Needle", spaceNeedleLocation);
    
                // If you set the geocoordinate parameter to null, the label parameter is used as a search term.
                LabeledMapLocation spaceNeedleLML = new LabeledMapLocation("Space Needle", null);
    
                mapsDirectionsTask.End = spaceNeedleLML;
    
                // If mapsDirectionsTask.Start is not set, the user's current location is used as the start point.
    
                mapsDirectionsTask.Show();
    
    
    
Important Note:

You must specify at least one of Start or End, or an exception is thrown when you call the Show method.

See Also

Reference

BingMapsDirectionsTask

LabeledMapLocation

GeoCoordinate

Other Resources

How to use the Bing Maps task for Windows Phone 8