Jerry Nixon on Windows

Monday, June 18, 2012

Easily include Bing Map data in your Windows 8 Metro App

There’s no question how awesome Bing Maps is. It is loaded with innovation and tons of awesome data that now you can include in your application by using their REST based services. The services provide a lot of value to developers and their apps including data source management:

New: Bing Maps Account Center now provides the ability to manage data sources created by Data Source Management API (Bing Spatial Data Services). You can now use the Manage my data sources page to view and edit all the data sources associated with your account in one place.

There are four API services:

Locations API - Use the Locations API to geocode and reverse-geocode location data.

Imagery API - Use the Imagery API to get a static map and imagery data information such as map tiles and providers.

Routes API - Use the Routes API to get directions and route information for driving, walking or using transit.

Traffic API - Use the Traffic API to get information about traffic incidents and issues in a specified area.

This article will be using the Locations API specifically. Using this we can leverage data from other services like Bing’s Search and plot them on a map control.

The are three Location API queries:

Find a Location by Address Use these URL templates to get latitude and longitude coordinates for a location by specifying values such as a locality, postal code, and street address.

Find a Location by Point Use this URL template to get the location information associated with latitude and longitude coordinates.

Find a Location by Query Use these URL templates to get latitude and longitude coordinates that correspond to location information provided as a query string.

This article will implement all three of these methods – yep, all of them. Each has their own use and implementing just one would be a sick waste of time. So here it goes.

First, get a key

The Bing Maps Portal is where you start. A developer key is quick, simple, and free. In fact, using the Bing Map services is completely free. That’s great. Once you have your key, we can really get started.

Second, copy my helper

It never gets old for things to be easy. I created this helper to be helpful. You might want to use it. You might want to copy it. You might want to amend it. I don’t care what you do with it. I just hope it helps a little – and that you send me a note letting me know it worked for you.

That’s it. The helper is just a method call away and, presto, you have the data you want thanks to the Bing Maps REST service. It’s worth pointing out that there’s an SDK, too. It’s up to you how you access the data. But if your needs are simple, my helper might be all you ever need. Otherwise, Bing Maps has a forum (here) in case you hit any issues.

Conclusion

For all you lawyers out there, you will likely want to check out the Terms of Use specifically for Windows 8 Metro applications. In particular, read this:

The reality is, those terms are not very restrictive. And Bing Maps is a powerful platform to leverage. If, for some reason, Bing Maps doesn’t suit you. Consider Yahoo! geocoding services – tey also integrate into WinRT applications easily. It’s not as powerful, sure, but it’s cool to have options.

Hey! I'm Jerry Nixon, a Microsoft Developer Evangelist in Colorado. If you are into Windows and Windows Phone, you are at the right place. I blog, I teach, and I speak; should you see me out somewhere, say hi! Thanks for your visit.