How to use the Bing Maps directions task for Windows Phone 8

August 19, 2014

Applies to: Windows Phone 8 and Windows Phone Silverlight 8.1 | Windows Phone OS 7.1

The Bing Maps directions task launches the Bing 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 Bing 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 noteImportant Note:

The Bing 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 Bing Maps is unavailable in their location.

To use the Bing 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
    Imports 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 bingMapsDirectionsTask as BingMapsDirectionsTask = new BingMapsDirectionsTask()
                
    ' 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)
    
    bingMapsDirectionsTask.End = spaceNeedleLML
    
    ' If bingMapsDirectionsTask.Start is not set, the user's current location is used as the start point.
    
    bingMapsDirectionsTask.Show()
    
    Important noteImportant Note:

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

Show:
© 2014 Microsoft