Compartilhar via


How to use the Bing 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 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 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.

    using Microsoft.Phone.Tasks;
    using System.Device.Location;
    
    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.

    BingMapsDirectionsTask 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.
    LabeledMapLocation spaceNeedleLML = new LabeledMapLocation("Space Needle", null);
    
    bingMapsDirectionsTask.End = spaceNeedleLML;
    
    // If bingMapsDirectionsTask.Start is not set, the user's current location is used as the start point.
    
    bingMapsDirectionsTask.Show();
    
    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 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