Introduction
Hi, today I am gonna show you that how to draw route between two location points in windows phone 8 application using Bing Maps Direction Task.
Bing Map Direction Task is a built in launcher in windows phone which takes two location points and display the route between them by launching Bing Maps.
To use Bing Map Direction Task we need to add library or namespace Microsoft.Phone.Tasks and System.Device.Location in our MainPage.xaml.cs
Location A Coordinates : 40.782946,-73.965369Location B Coordinates : 40.727586,-73.992433
1- Create New Windows Phone Silverlight Blank App.
2- Open MainPage.xaml from solution explorer.
3- Remove all content in designer and Add Button, change its Name to "directionbutton" and content to "Get Direction" from properties panel and create its Click Event.
4- Now your MainPage.xaml designer will look like in the picture below
5- Open MainPage.xaml.cs Add Microsoft.Phone.Tasks and System.Device.Location namespace with other namespaces at the top of the page.
Now your code will look like this
6- Now add the code given below inside the direction button click event
// Creating new Object of Bing Maps Directions Task and Intialize it with Starting and Ending Location Points
BingMapsDirectionsTask bing = new BingMapsDirectionsTask()
{
//Giving label and coordinates to starting and ending points.
Start = new LabeledMapLocation("Location A", new GeoCoordinate(40.782946, -73.965369)),
End = new LabeledMapLocation("Location B", new GeoCoordinate(40.727586, -73.992433))
};
// Launching Bing Maps Direction Tasks
bing.Show();
Now your code in MainPage.xaml.cs will look like this
7- Clean the solution and from build menu, build it and deploy it in emulator or windows phone.
8- After launching application you will see a blank page with one button you added. like the picture below
Click the Get Directions Button and you will see new application will automatically launch that is called launcher. And will show you many information about your route.
1- It will draw route between two given point.
2- It will display time required to cover distance.
3- You can check route and other information for driving cars, bus and pedestrian.
4- It will provide you suggestion to take left or right after some specific distance.
5- By starting voice navigation you will get suggestions via voice.
6- Route steps show you all steps to follow route.
Bing Map Direction Task is a built in launcher in windows phone which takes two location points and display the route between them by launching Bing Maps.
To use Bing Map Direction Task we need to add library or namespace Microsoft.Phone.Tasks and System.Device.Location in our MainPage.xaml.cs
Requirements
There is nothing special required to use Bing Map Direction Task. The only thing before doing this is to know about the Location Class, Launchers and choosers for windows phone and two location points between which we have to draw route.
Assume that we have two location points
Implementation
Now we will implement Bing Maps Direction Task to draw route.1- Create New Windows Phone Silverlight Blank App.
2- Open MainPage.xaml from solution explorer.
3- Remove all content in designer and Add Button, change its Name to "directionbutton" and content to "Get Direction" from properties panel and create its Click Event.
4- Now your MainPage.xaml designer will look like in the picture below
5- Open MainPage.xaml.cs Add Microsoft.Phone.Tasks and System.Device.Location namespace with other namespaces at the top of the page.
Now your code will look like this
6- Now add the code given below inside the direction button click event
// Creating new Object of Bing Maps Directions Task and Intialize it with Starting and Ending Location Points
BingMapsDirectionsTask bing = new BingMapsDirectionsTask()
{
//Giving label and coordinates to starting and ending points.
Start = new LabeledMapLocation("Location A", new GeoCoordinate(40.782946, -73.965369)),
End = new LabeledMapLocation("Location B", new GeoCoordinate(40.727586, -73.992433))
};
// Launching Bing Maps Direction Tasks
bing.Show();
Now your code in MainPage.xaml.cs will look like this
7- Clean the solution and from build menu, build it and deploy it in emulator or windows phone.
8- After launching application you will see a blank page with one button you added. like the picture below
Click the Get Directions Button and you will see new application will automatically launch that is called launcher. And will show you many information about your route.
1- It will draw route between two given point.
2- It will display time required to cover distance.
3- You can check route and other information for driving cars, bus and pedestrian.
4- It will provide you suggestion to take left or right after some specific distance.
5- By starting voice navigation you will get suggestions via voice.
6- Route steps show you all steps to follow route.
Conclusion
We have learned to draw a route between two different location using Bing Maps Directions Task by giving starting and ending points to it.
Sample
Below is the sample you can download it and can get help from it also.
very informative . .
ReplyDeleteI wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post. the page
ReplyDelete