Thursday, June 14, 2012

Get Directions with Bing Maps using Geocordinates.

With Bing Map API, you can easily get the directions to some place. You only need to know  the start location and end location. If this start location is not specified, your current location is treated as the start.

In this tutorial we use Bing Maps Directions Task which is one of the many launchers bundled with Windows Phone7 Mango series. Hopefully, they make developer's life easy. They are really useful when integrate social sharing features to your applicaton. Otherwise you need to deal with OAth protocol for a considerable amount of time. You do not need to touch those dirty ...
Enough  pep talk. Let's get started.

You have two options to enter location details either by text based or geocordinates which are in latitude and longitude format. These two methods are demonstrated below.

Text based location

[sourcecode language="csharp"]
BingMapsDirectionsTask bmDirectionTask = new BingMapsDirectionsTask();
LabeledMapLocation start = new LabeledMapLocation("Sydney", null);
LabeledMapLocation end = new LabeledMapLocation("Perth", null);
bmDirectionTask.Start = start;
bmDirectionTask.End = end;
bmDirectionTask.Show();
[/sourcecode]

Based on geocordinates

[sourcecode language="csharp"]
BingMapsDirectionsTask bingMapsDirectionsTask = new BingMapsDirectionsTask();

GeoCoordinate userLocation = new GeoCoordinate(33.8683,151.2086);
LabeledMapLocation start = new LabeledMapLocation("From", userLocation);
bingMapsDirectionsTask.Start = start;

GeoCoordinate placeLocation = new GeoCoordinate();
LabeledMapLocation end = new LabeledMapLocation(31.9554,115.8585);
bingMapsDirectionsTask.End = end;

bingMapsDirectionsTask.Show();
[/sourcecode]

No comments:

Post a Comment

How to enable CORS in Laravel 5

https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...