Using the BingMapsDirectionsTask in Windows Phone Mango

Do you want to display the direction between 2 locations from your Windows Phone 7 Application ? If yes , BingMapsDirectionsTask launcher in the Windows Phone SDK might help you .

The BingMapsDirectionsTask launcher will launch the Bing Maps App on your Windows Phone and shows the driving direction between 2 points .

Using the BingMapsDirectionsTask in your Windows Phone App is easier .

Add reference to the System.Device assembkly to your Windows Phone Project and include the following namespaces .

using Microsoft.Phone.Tasks; using System.Device.Location;

Create an instance of the BingMapsDirectionsTask and assign the start or end location for which you want to display the direction .

The start and the End properties of the BingMapsDirectionsTask accepts the values of type LabeledMapLocation . The LabeledMapLocation represents the geographic coordinate or the name .

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
//using System.Device.Location;
namespace PhoneApp5
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
BingMapsDirectionsTask Direction = new BingMapsDirectionsTask();
LabeledMapLocation start = new LabeledMapLocation("Indiranagar , Bangalore", null);
LabeledMapLocation End = new LabeledMapLocation("Koramangala , Bangalore", null);
Direction.Start = start;
Direction.End = End;
Direction.Show();
}
}
}

After setting the start and the end position , call the Show method of BingMapsDirectionsTask to launch the BingMap App .

This is what MSDN states about BingMapsDirectionsTask

“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.”

References

 

Leave a Reply