Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using the BingMapsDirectionsTask in Windows Phone Mango

DZone's Guide to

Using the BingMapsDirectionsTask in Windows Phone Mango

· Mobile Zone
Free Resource

Do you want to display the directions between 2 locations from your Windows Phone 7 Application? 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 makes it simple to add this functionality.

 

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."





Source: http://windowsphonerocks.com/Developer/DeveloperArticles/tabid/64/Article/168/using-the-bingmapsdirectionstask-in-windows-phone-mango.aspx
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}