Update 2011-09-30: This article is compatible with the final version of Windows Phone 7.1 "Mango".
The next version of Windows Phone 7 will introduce a set of new tasks that allow your applications to launch and use additional built-in features of the phone. One of these tasks is the BingMapsDirectionsTask. Unlike the task we've looked at in the previous post that allows you to center the map on a specific location, this one supports a start and end location to display turn-by-turn driving directions.
The sample application allows you to enter both start and end locations for the directions task.
This already produces a nice experience, and it's fully functional in the emulator (including speech output):
The interesting detail is that you can leave out the coordinates and only use the description. Unlike the BingMapsTask which relies on those coordinates, the directions task allows you to perform a search based on a descriptive string.
In that case, when you launch the task, you are first asked about alternatives if multiple potential matches for your description have been found:
Another noteworthy detail is that if you leave out the start position completely, Bing Maps assumes you want to get directions to the end position from your current position. Similarly, if you leave out the end position, directions are generated from the start to your current position.
The code to all this is very simple:
// create the task var task = new BingMapsDirectionsTask();
task.Start = new LabeledMapLocation(startLabel, startCoordinate);
task.End = new LabeledMapLocation(endLabel, endCoordinate);
// go task.Show();
To use the involved GeoCoordinate class in the System.Device.Location namespace, you need to add a reference to the System.Device assembly to your project first.
Unfortunately speech synthesis seems only be available when the phone is using English settings. I couldn't get it to work with other languages.
Using this task is extremely simple, and since providing latitude and longitude based coordinates is optional, you can get impressive results quickly without using a separate geocoding service, simply by providing descriptive location names. The download provided here contains the sample you can see in the above screenshots.