Migration Guide
Bing Maps V6.3 to V8 Bing Maps V6.3 to V8 Migration Guide
Table of Contents 1.0 Introduction ...... 3 1.1 Purpose of this Guide ...... 3 1.2 But I’m not using v6.3, I’m using v5 or 6.x ...... 3 1.3 Why Bing Maps v8? ...... 3 1.4 Service Comparison...... 3 1.5 Notable Changes ...... 6 1.6 Suggested Migration Plan ...... 6 1.7 Next Steps ...... 6 1.8 Technical Resources ...... 6 2.0 Authentication ...... 7 2.1 Getting a Bing Maps Key ...... 7 2.2 How to authenticate the map ...... 7 3.0 Localization ...... 9 4.0 Mapping Examples ...... 10 4.1 Loading a Map ...... 10 4.2 Map Navigation ...... 12 4.3 Geocoding ...... 14 4.4 Reverse Geocoding ...... 15 4.5 Adding a Pushpin ...... 16 4.6 Adding Shapes ...... 17 4.7 Shape Layers & Collections ...... 19 4.8 Displaying Routes ...... 20 5.0 Additional Bing Maps Tips ...... 25 5.1 Optimizing Transactions with the REST services ...... 25 5.2 Bing Maps V8 Tips & Tricks ...... 25 5.3 Determining a User’s Location ...... 28 6.0 Useful Tools & Support ...... 30 6.1 Migration Support ...... 30 6.2 Bing Maps Blog ...... 30 6.3 Bing Maps v7 Modules CodePlex project ...... 30 Appendix A: Bing Maps v6.3 to v8 class Mapping ...... 31 A1: Class Type Mapping ...... 31
Bing Maps V6.3 to V8 Migration Guide
A2: Map Functions Mapping ...... 33
Bing Maps V6.3 to V8 Migration Guide
1.0 Introduction 1.1 Purpose of this Guide This guide is designed to support you in your Bing Maps migration from version 6.3 to version 8. This resource provides detailed comparisons between the JavaScript API of these two versions of Bing Maps as well as comparative code samples, migration suggestions and best practices for migrating your code to the newest version of Bing Maps. As you read this document you should gain an understanding of the benefits of Bing Maps v8 and how to leverage it in your existing mapping applications. 1.2 But I’m not using v6.3, I’m using v5 or 6.x It is possible that your application appears to be pointing to older versions of Bing Maps (i.e. v6.2 or v5), however these versions are actually redirecting to the v6.3 control on the backend and have been doing so for over 6 years. So in reality your application is using v6.3. 1.3 Why Bing Maps v8? The version 6.3 of Bing Maps has been around for over 7 years and hasn’t seen any code updates since the release of Bing Maps v7, 6 years. Version 8 of Bing Maps was just recently released and offers numerous advantages over both v6.3 and v7, including:
Faster and more fluid map control A cleaner, more modern, programming model Increased culture support World Wrap support Improved Routing Capabilities Traffic data available in outside of the US Ability to optimize transactions using map sessions Mobile browser support Many new features 1.4 Service Comparison The Bing Maps v8 web control is the recommended migration path from v6.3. There is a small learning curve as there has been some notable improvements made in the code syntax from v6.3 to v8.
Faster and more fluid map control
When it comes to performance the v8 is miles ahead of v6.3. Version 8 is capable of rendering data much faster than versions 6.3 and 7, and can also render a lot more data too. When dealing with small data sets on a standard browser this might not be that noticeable but if you need to display a large data set or are using a mobile browser this increased performance makes a big difference. Noticeable performance issues in v6.3 have generally occurred when 200 or more pushpins have been added to the map, while v8 is capable of rendering thousands of pushpins and polygons with good performance.
A cleaner, more modern, programming model.
One of the most notable changes in v8 is that the API uses a Microsoft namespace. Doing this significantly reduces code conflicts between 3rd party JavaScript libraries. This also significantly speeds up the map control as there are less global variables for the browser to keep track of. In v6.3 the code
Bing Maps V6.3 to V8 Migration Guide
was made to be backwards compatible with previous versions of Bing Maps. This was a nice feature but resulted in the map control growing significantly and in some cases multiple functions were created that did the same thing thus making the API much more confusing to use than needed. Version 8 also uses a modular framework. Many features of the map API are needed when the page loads. By modularizing the API additional features can be loaded when need, often sometime after the page has loaded. As a result, the initial JavaScript downloaded which contains the core functionalities needed to load the map and display data on it is significantly smaller than the JavaScript downloaded by v6.3.
Increased culture support
Version 6.3 supported 22 different culture codes (languages). Version 8 supports significantly more culture codes and uses the Bing Maps REST services to perform geocode and route requests which has support for 117 languages.
World Wrap Support
In v6.3 of Bing Maps the map consisted of a single map that was disconnected at the edges. In reality we know that the far edges of the map wrap around and attach in real life but we can’t see this in v6.3. This becomes an issue if you want to represent information that crosses that edge. In v6.3 if you try and draw the shortest path between Sydney Australia and Los Angeles, USA it would take you across the full map. In v8 the map wraps around such that we can continually pan left or right just as if you were to spin a globe. In addition to this if you were to repeat the previous task of drawing a shortest path, v8 would draw the line going over the Pacific Ocean which is the shortest most logical route to take. Overall this makes for a much better user experience.
Improved routing capabilities
In v8 not only can you easily render routes on the map but users can also drag the route using the mouse if they wanted to modify it to go through a certain area or avoid another. In addition to this the directions module also generates nicely formatted directions for you with keyword bolding, and turn by turn icons. So no more having to generate HTML from the raw route data like you have to with v6.3. In addition to this hovering over one of the instructions shows you where that location is on the map. The direction module also has an optional input panel you can display which can save you a lot of development. Version 8 also provides driving, walking and transit directions.
Traffic data outside of the US
Traffic data has been available in Bing Maps for a number of years, however, in earlier versions of Bing Maps it was only available in the US. In v8, traffic data is available in 35 countries.
Bing Maps V6.3 to V8 Migration Guide
Ability to optimize transactions using map sessions
In v7 the concept of map sessions was introduced and has been carried over to v8. When one of the interactive Bing Maps map controls is loaded, a special Bing Maps key, called a session key, can be retrieved from the map and uses to access the Bing Maps REST and Spatial Data Services. Any transactions occurred using the session key as non-billable in the reports. A session starts when a map is loaded and ends when the browser is closed, the user leaves the page, or the page is refreshed. This can help significantly reduce the number of billable transactions that get generated by your application and as a result make a big difference in terms of licensing by potentially lowering your overall billable usage.
Mobile browser support
Not only is v8 supported in most modern desktop browsers, it is also supported on all major mobile browsers as well.
Many new features
Over the years Bing Maps customers and developers have requested number of new features and functionalities. Many of these are now available in v8. Some of the most notable one’s being;
Bing Maps V6.3 to V8 Migration Guide
1.5 Notable Changes As mentioned in the previous section, the v8 control has been redesigned from the ground up and as a result there are some significant syntax changes in the API. In addition to these changes other notable changes include:
3D functionality removed
The Bing Maps 3D control was released as a beta control over a decade ago. It was originally developed using Active-x which required an add-in to be installed into your browser. Since the original release of this control web technology has changed significantly. The Bing Maps team announced the deprecation the 3D control in November 2010 and officially deprecated it in December 2011. Even though it was deprecated it has been left online so as not to break applications built on top of v6.3. If you require a 3D map control, we recommend taking a look at the Windows 10 UWP map control which provides rich 3D maps that are significantly more detailed than what was available in v6.3. 1.6 Suggested Migration Plan To assist you with planning, we have compiled this list of high‐level steps to use as a baseline plan to move your codebase and development practices to version 8 equivalents. While your ultimate plan will depend on your specific situation, the following steps outline suggested components of any effort:
1) Review existing application and identify where Bing Maps v6.3 code is being used. 2) Identify which features of Bing Maps v6.3 are being used and review the migration information in this document or Appendix A: Bing Maps v6.3 to v8 class Mapping. 3) Migrate code to version v8 of Bing Maps and update script reference to point to the new v8 map control URL. 4) Test your migrated application. 5) Deploy your application to your production environment. 1.7 Next Steps The remaining sections of this migration guide provides sample code that introduces you to the basics of how to leverage the most commonly used v6.3 functionality using the v8 API. You will also find discussions on the differences in the general development cycle and authentication between the two platforms. 1.8 Technical Resources Here is a list of useful technical resources for the Bing Maps v8 web control.
Bing Maps v8 Interactive SDK Bing Maps v8 documentation Bing Maps MSDN documentation (All Bing Maps APIs) Bing Maps MSDN Forums Bing Maps Dev Center Bing Maps REST Services (MSDN) Bing Spatial Data Services (MSDN) Bing Maps Terms of Use
Bing Maps V6.3 to V8 Migration Guide
2.0 Authentication The Bing Maps terms of use states that you must use proper authentication credentials when using Bing Maps SDK. However, the v6.3 control did not throw an error if credentials were not provided. As a result, there has been a number of production applications released that are not properly authenticated. If you do not have a Bing Maps key, you will need this to authenticate the Bing Maps v8 control and to access any of the Bing Maps services. 2.1 Getting a Bing Maps Key There are two functions in which you can get a Bing Maps key. This first function is recommended if you fall into one of these categories;
Are an enterprise customer who has a volume license agreement with Microsoft. Currently generate more than 500 thousand transactions a month. Documentation on transactions can be here. Are using Bing Maps in an asset tracking application. Internal applications where you prefer to use a known user license (cost per user) rather than a transactional license.
The second function is recommended for all other applications that generate less than 500 thousand transactions a month.
Method 1: Create a Bing Maps Account
1) Create a Bing Maps account at the Bing Maps Dev Center. You can find documentation on how to create a Bing Maps account here. 2) Create a Bing Maps key. a. We invite you to use the “basic” key type and free use terms outlined in the Bing Maps Terms of Use (TOU) as you migrate to Bing Maps. Production applications outside the free use thresholds in the TOU will need a Bing Maps Enterprise account. For assistance with Bing Maps licensing, please contact [email protected] (including your Bing Maps Account Center ID). b. Enterprise customers are advised to use keys of type “basic” for all pre‐production application testing. An enterprise key should be created and used for production use. c. See the MSDN documentation for more information on Getting a Bing Maps key.
Method 2: License Bing Maps through Azure Marketplace
Sign up for the Bing Maps API for Enterprise in the Azure Marketplace here. If you do not have an Azure account, you will have to create one and provide a credit card. Fill out the forms provided and select the transaction level that meets your monthly transaction requirements. Note that you can change this at any time. One benefit of license Bing Maps through the Azure Marketplace is that you get the flexibility of licensing on a month to month basis, rather than being locked into a contract for one of more years. 2.2 How to authenticate the map This section of the migration guide discusses the differences in authentication functions between the v6.3 and v8. The main difference between these versions is that v6.3 requires you to create a map object, set the credentials on it and then load it, where as in v8 this all gets done with one line of code.
Bing Maps V6.3 to V8 Migration Guide
Additional the URL to version 8 has changed completely to align with the newer Bing branding, and to also reduce confusion about the meaning of “dev” in the v6.3 URL.
Before: v6.3
In v6.3 authentication of the map occurs by passing in a Bing Maps key into the maps SetClientToken or SetCredentials function before calling the LoadMap function. You can load the map control by adding a script reference to the API:
You would then create an instance of the map object and specify your credentials: var map = new VEMap('myMap'); map.SetCredentials('Your Bing Maps Key'); map.LoadMap();
Where 'mapDiv' is the id of the DIV element on the page that contains the map.
After: v8
The v8 control requires specifying authentication credentials when creating a new instance of the map, otherwise an error message appears on top of the map. First change the script reference to Bing Maps to version 8 like so:
You can then create an instance of the map object and specify your credentials: var map = new Microsoft.Maps.Map('#myMap', { credentials:'Your Bing Maps Key' });
Where 'mapDiv' is the id of the DIV element on the page that contains the map.
The script reference used above will load the map components synchronously as needed. Version 8 also supports asynchronous loading of the map control as well which is recommended for better page load performance. When loading the map script asynchronously you will need to provide the name of a callback function that will be called when the map script has been downloaded. Here is an updated map script reference that calls a GetMap function wen the script has finished downloading.
Bing Maps V6.3 to V8 Migration Guide
3.0 Localization Localization of maps is the process of rendering maps in a specific language other than the default. Both v6.3 and v8 support localization. Version 6.3 required that you pass in a culture code to set the language of the map, however version 8 automatically tries to detect the appropriate culture code for a user based on their browser settings and location. This saves a lot of work in trying to manage the culture of the map yourself. However, like v6.3 it is possible to specify a culture code, which will override the default behavior. This is useful when testing, or if you only want the map to support a single language. If you do wish limit the map to a single language, the following is an example of how this was done in v6.3 and how it can be done in v8.
Before: v6.3
To get a localized map using v 6.3, add an mkt parameter to the API script reference.
Bing Maps V6.3 to V8 Migration Guide