Book Image

Learning Bing Maps API

By : Artan Sinani
Book Image

Learning Bing Maps API

By: Artan Sinani

Overview of this book

Provided as a part of Microsoft's Bing suite of search engines, Bing Maps is a web mapping service powered by the Bing Maps for Enterprise framework. The need for geospatial data has increased dramatically in the last few years. Adding a mapping context to any location-based data is becoming more and more common, and businesses are embracing it to improve their user experience with new data richness. Comprising of simple, follow-along examples, Learning Bing Maps API will show you how to use the many features of Bing Maps, from dropping a simple map on a web page, to fetching geospatial data from the Microsoft servers. Through the course of this book you will build a solid foundation for creating your own geo-applications.Following the hands-on recipes of this book, you will build a different web app in each chapter as you communicate with different APIs provided by Bing Maps. You will build your own library of JavaScript modules that talk to the Microsoft Maps API.You will create a custom theme for the map, with your own controls. Taking advantage of the global reach of Bing Maps, you will learn how to build a route scheduler for a delivery company in Madrid, Spain, and then you will discover how to create jobs on the Bing Maps servers for geocoding addresses in California, USA. By the end of the book you will have learned everything you need to know to embed a map on a web page, with your own geo-data, or data obtained by the Bing Map Services.
Table of Contents (14 chapters)

Websites


Now, let's add a basic ASP.NET MVC project to our VS solution named LBM.Geocoder.Web. The website is very similar to the one we built in the previous chapter, so we can copy HomeController.cs, _Layout.cshtml, the Index.chtml views, app.js, app.css, learningTheme, and BundleConfig.cs from it.

Next, we create a new JavaScript module, geocoder.js, and save it inside the Scripts folder:

lbm.Geocoder = function(map, $) {
    this._map = map;
    this.$ = $;
    this._addCss();
};
lbm.Geocoder.prototype = {
    _addCss: function () {
        var link = document.createElement('link');
        link.setAttribute('rel', 'stylesheet');
        link.setAttribute('href', '/Content/geocoder.css');
        var head = document.getElementsByTagName('head')[0];
        head.appendChild(link);
    }
};
Microsoft.Maps.moduleLoaded('lbm.Geocoder');

We also pass a $ argument to the module, in the shape of an object that will perform AJAX requests (in our case jQuery), using the good practice of dependency...