Getting Started Building Offline Maps App for Windows

NOTE: An updated version of this article can be found in the Microsoft Maps Blog.
https://www.microsoft.com/en-us/maps/news/getting-started-building-offline-maps-app-for-windows

offline_Surface_Go.jpg

Bing Maps API offers a lot of different features in online mapping apps developers can create, from large-scale commute calculations to optimizing routes for thousands of agents. But in some cases, you don’t have internet access and for that, Bing Maps and the Windows Developer Platform UWP have what you need to build your own offline maps app for Windows.

To bring offline maps into your Windows application, you’re going to need a Bing Maps account to create a key. If you don’t already have one, you can create a key for free and start building offline mapping experiences right away!

Developing for Windows

There’s a distinction between developing web apps using V8 Web Control and developing dedicated apps for Windows platforms - including tablets, phones, and desktops. For the purposes of this article, we’ll be looking at dedicated Windows app development for offline maps development.

Bing Maps API works natively with the Windows Presentation Foundation (WPF), a framework designed to create versatile Windows client apps with offline functionality. Developers can use WPF to create powerful apps that integrate mapping, media playback, and design features. The WPF feature developers need for building offline maps apps is the MapControl service.

You’ll be prompted for your Bing Maps API key here before you can use any MapControl features. Once you’ve authenticated your key, you can display both 2D and 3D maps in your application.

You’ll have the option to display a map in a lightweight, compact placecard or in a control. The benefit of using placecards is that they’re handy for pages that don’t require a ton of info or customizability on the map. If you use a control, users will be able to use the offline map freely without having to leave your app at all.

Microsoft Maps app showing offline map

Integrating Maps Services for Your App

Once you’ve placed your map, you’ll be able to access additional map services, including points of interest and offline mapping. With updates to Bing Maps API, users no longer have to go to the settings app to download maps.

Use the Windows.Services.Maps.OfflineMaps classes to search for and download all the map packages your app needs. The OfflineMapPackage class is used as a signifier for data pertaining to different map regions, the app will then use this class as an indicator for the data it needs to download. 

private async Task getMapPackages()
{
    Geopoint myPoint = new Geopoint(new BasicGeoposition()
    {
        //Geopoint for Seattle
        Latitude = 47.604,
        Longitude = -122.329
    });

    var queryResult = await OfflineMapPackage.FindPackagesAsync(myPoint);

    if (queryResult.Status == OfflineMapPackageQueryStatus.Success)
    {
        foreach (OfflineMapPackage package in queryResult.Packages)
        {
            if (package.Status != OfflineMapPackageStatus.Downloaded)
            {
                var downloadRequestResult = await package.RequestStartDownloadAsync();

                if (downloadRequestResult.Status == OfflineMapPackageStartDownloadStatus.Success)
                {
                    // do something with the offline map package.
                }
            }
        }
    }
}


In the example above, the OfflineMapClass is directed to create a GeoPoint for Seattle using the provided coordinates. The app will then look for that particular map package. If the search is successful, it’ll download the package. Depending on what your new application needs, you can use as many GeoPoints as required.

For an alternative, the MapControl also supports GeoboundingBox for downloading map packages. This is more useful in situations that require customizable boundaries to define the area that needs to be downloaded.

It’s worth noting that users will have to be online at least once for the app to download the necessary packages for offline map functionality. Check out our GitHub sample for a reference on how to implement offline mapping.  

Simplify building offline maps for Windows with Bing Maps API

With the Bing Maps API, it’s easy for developers of every skill level to create robust mapping experiences that can service thousands of concurrent users - online or offline. All it takes to get started with development is a key. Learn more about our API licensing options for your project.