Cloud Training (Online)




Windows Phone 8.1 and Windows Runtime Apps How to #18 – Display Bing Map in Windows Phone 8.1

Windows Phone 8.1 SDK provides the Uri scheme called bingmaps: which lets the developers to display a map using the built-in Maps apps from their app.

The bingmaps Uri scheme in Windows Phone 8.1 is the alternative to the MapsTask that was available in Windows Phone 8.

How to display Bing Map in Windows Phone 8.1 ?

To launch the Bing Map in Windows Phone 8.1 using bingmaps: Uri scheme , we must use the Launcher.LaunchUriAsync method.

Below is a sample code snippet demonstrating the use of Geolocator class to get the current location and display it in the Built in Map using the bingmaps: Uri scheme.

async private void Button_Click(object sender, RoutedEventArgs e)
{
    Geolocator geo = new Geolocator();
    Geoposition position = await geo.GetGeopositionAsync();
    string uri = @"bingmaps:?cp=" + position.Coordinate.Point.Position.Latitude + 
           "~" + position.Coordinate.Point.Position.Longitude + "&lvl=17";
    var retValue = await Windows.System.Launcher.LaunchUriAsync(new Uri(uri));

}

In the above code cp attribute is used to indicate that the map is centered around the current location and “lvl” refers to the zoom level.

image

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.