Friday, October 28, 2011

New Launchers and Choosers in Mango Unleashed Part I- Bing Maps Integration

Folks,
In this blog, we are going to discuss new launchers available in Mango - Bing Map Integrations!! The two launchers available in Mango are -
1. BingMapDirectionsTask - This task takes two parameters- Start and End locations and will give you directions on Bing Map to navigate from Start to End Location.
2. BingMapTask - This task will pin point the location or Search term on the Bing map.

What has changed?
Earlier to implement the Bing Map API functionality, the developers used to get a key and use web Service APIs to build routes on maps and pin-point locations on maps which required a lot of effort and learning.

With these two launchers and maximum of 3-4 lines of code, you can implement this functionality fairly easily.

Implementation

BingMapTasks
The important properties of this launcher are  -
1. Center - It if of type GeoCo-ordinate. If this is not set, then the user's current location will become the center. This location is used as center point for the map.
2. SearchTerm - This is a string and it is used to search and tag locations on the map. It can be the name of the place, type of place or anything else.
3. ZoomLevel - This gets the initial zoomlevel of the map.

Code for BingMapTasks -

BingMapsTaskbingMapTask = new BingMapsTask();

bingMapTask.ZoomLevel = 1.0;

bingMapTask.SearchTerm =
"Chandigarh,India";

bingMapTask.Show();

BingMapDirectionsTask

This launcher will give you directions to reach from a Start to End Location. It has two properties-
1. Start - LabeledMapLocation which can be determined either with a label (like "Patiala,India) or a Geo-cordinate
2. End - Same as Start.

The following is the code to implement this launcher -
BingMapsDirectionsTask directionsTask = new BingMapsDirectionsTask();

LabeledMapLocation startLocation = new LabeledMapLocation();

startLocation.Label ="Patiala,India";

LabeledMapLocation endLocation = new LabeledMapLocation();

endLocation.Label = "Chandigarh,India";

directionsTask.Start = startLocation;

directionsTask.End = endLocation;

directionsTask.Show();



If you want the Geo-coordinates of location, you can use the emulator to find that out in the following manner -

On the windows phone emulator press the ">>" option available on top right hand side. A window will open, click on Location tab and then enter the location for which you need to retrieve Latitude and Longitude -

Using the latitude and longitude, you can create the instance of GeoLocation. (You need to add reference of System.Device.dll)

System.Device.Location.GeoCoordinate coordinate = new System.Device.Location.GeoCoordinate(30.3280, 076.3849);



No comments:

Post a Comment