How to request driving or walking directions for Windows Phone 8

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

This topic describes how to write an app that requests driving or walking directions to a specified destination from another app installed on the phone. You request directions by using the ms-drive-to or ms-walk-to Uri scheme.

Tip

This topic describes how to write code that requests directions from another app installed on the phone. The user may have more than one installed app that can handle requests for directions. When you use the method described in this topic, the user can choose which app to use to display the directions. If you simply want to display directions, you can also use the Maps directions task, which launches the built-in Maps app. For more info, see How to use the Maps directions task for Windows Phone 8.

For a sample that demonstrates some of the tasks described in this topic, download the Navigation URI scheme sample.

For more info about using a Uri to launch another app, see Auto-launching apps using file and URI associations for Windows Phone 8. For info about how to write an app that responds to requests for directions, see How to respond to requests for directions for Windows Phone 8.

The following screen shot shows a built-in app that lets the user request driving directions to the selected destination.

This topic contains the following sections.

Format of the Uri

  • Format
    The Uri to launch the request for directions has the following format:

    ms-drive-to:?destination.latitude=<latitude>&destination.longitude=<longitude>&destination.name=<name>

    ms-walk-to:?destination.latitude=<latitude>&destination.longitude=<longitude>&destination.name=<name>

    You don’t specify the starting point in the request. The starting point is assumed to be the current location.

    You do not have to encode the Uri or the name value.

  • Example
    The following example shows the Uri to request directions to the city of Redmond, Washington, in the United States:

    ms-drive-to:?destination.latitude=47.6451413797194&destination.longitude=-122.141964733601&destination.name=Redmond, WA

    ms-walk-to:?destination.latitude=47.6451413797194&destination.longitude=-122.141964733601&destination.name=Redmond, WA

Requesting directions

The following code sample shows how to request driving directions to a specified destination from another app installed on the phone. After this sample gets the required parameter values, it assembles them into a Uri . Then it calls the Uri with the LaunchUriAsync method.

To request directions

  1. In Visual Studio, create an empty new Windows Phone project.

  2. In the code-behind file for the main page, paste the following method.

            async void RequestDirections()
            {
                // Get the values required to specify the destination.
                string latitude = "47.6451413797194";
                string longitude = "-122.141964733601";
                string name = "Redmond, WA";
    
                // Assemble the Uri to launch.
                Uri uri = new Uri("ms-drive-to:?destination.latitude=" + latitude + 
                    "&destination.longitude=" + longitude + "&destination.name=" + name);
                // The resulting Uri is: "ms-drive-to:?destination.latitude=47.6451413797194
                //  &destination.longitude=-122.141964733601&destination.name=Redmond, WA")
    
                // Launch the Uri.
                var success = await Windows.System.Launcher.LaunchUriAsync(uri);
    
                if (success)
                {
                    // Uri launched.
                }
                else
                {
                    // Uri failed to launch.
                }
            }
    
  3. In the constructor of the class, add a call to the RequestDirections method.

  4. Run the app.

    • If the emulator or phone does not have any apps that provide directions, you see a prompt to find an app in the Windows Phone Store.

    • If the emulator or phone has only one app that provides directions, that app starts automatically.

    • If the emulator or phone has several apps that provide directions, you see a prompt to select one of the apps from a list.

For info about how to write an app that responds to requests for directions, see How to respond to requests for directions for Windows Phone 8.