Windows 8 is shipped with preinstalled Maps application. This app provides all basic mapping features such us showing current location, searching for place or local business and calculating driving directions. Even better, Maps app implements bingmaps protocol to allow 3rd party applications to activate these features. There is just one disadvantage of the protocol: it’s basically a URL string and all numerous parameters need to be properly formatted.

WindowsMapsHelper library aims to simplify communications with Maps app. It encapsulates maps protocol into a few strongly typed classes.

How to install

PM> Install-Package WindowsMapsHelper

Open Maps app and show default map

await WindowsMapsHelper.MapsHelper.ShowMapAsync();

Select map area to display

The following example demonstrates map options. It opens map centered on downtown Toronto with traffic information.

var options = new MapOptions
    ZoomLevel = new MapZoomLevel(16),
    ShowTraffic = true,
    CenterPoint = new MapPosition(43.649126, -79.377885)

await WindowsMapsHelper.MapsHelper.ShowMapWithOptionsAsync(options);

Search points of interest

The following example searches for “tea” around London, UK. Note that method’s third parameter, options, is skipped to let Maps app to suggest the best view for the map.

await WindowsMapsHelper.MapsHelper.SearchAsync("tea", "London, United Kingdom", null);

Driving directions

var options = new MapOptions
    ShowTraffic = true,
    ViewStyle = MapViewStyle.Aerial

await MapsHelper.SearchDirectionsAsync(new MapAddress("Montreal"), new MapAddress("Ottawa"), options);

This code maps a route from Montreal to Ottawa. Map display mode is Aerial.

Next example demonstrates using coordinates for route searching.

await MapsHelper.SearchDirectionsAsync(null, new MapPosition(33.943538, -118.40812), null);

Addresses and coordinates can be mixed and start or stop location can be skipped to ask user to select this point manually.

Map options

MapOptions class helps to configure map view and provides the following fields:

Getting sources

WindowsMapsHelper source code is on GitHub.

blog comments powered by Disqus