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

Leave a Reply