Overview of the Bing Maps Trip Optimizer sample
This document describes the fundamental characteristics of the Bing Maps Trip Optimizer project, for example, how it's created and structured, and how it's built.
Note
The sample code that corresponds to this document is found in the Bing Maps Trip Optimizer Sample.
In this article
Creating the Visual Studio projects in Visual Studio
If you've downloaded and extracted the sample, you can open the TripOptimizer.sln solution file in Visual Studio, and you'll have the code in front of you. You can also view the source on the Bing Maps trip optimizer sample MSDN Samples Gallery page by selecting the Browse Code tab.
When we created the Visual Studio projects for Bing Maps Trip Optimizer, we used the JavaScript Blank Application template to create the main application project and the Visual C++ Windows Runtime Component template to create the C++ class library. The JavaScript project references the C++ project. The document Creating Windows Runtime Components in C++ explains how to set up a project reference.
For the JavaScript project, the Blank Application template provides the basic functionality that's required to run as a Windows 8.x Store app. Use this template to create an empty application. Visual Studio includes additional templates that provide enhanced initial functionality. Bing Maps Trip Optimizer uses the default files that come with the Blank Application template and adds additional image and code files.
One important project setting in the WinRT Class Library template is the /ZW option, which enables the program to use the Windows Runtime language extensions.
Warning
The /ZW option is not compatible with options such as /clr. This means that you can't target both the .NET Framework and the Windows Runtime from the same Visual C++ project.
Every Windows 8.x Store app on the Windows Store comes in the form of an app package. An app package contains a package manifest, which contains information about the app. For example, you can specify its capabilities, which define its access to protected system resources or user data. If you determine that your app requires certain capabilities, use the package manifest to declare them. Bing Maps Trip Optimizer specifies Internet (Client) to enable the app to access the Bing Maps Web services. For more information about app packages and capabilities, see .47EAAAFB-29AF-495C-A2D1-B2FF572D2631
For more information about the features and components that are available in the Visual Studio integrated development environment (IDE) for JavaScript, C++, and .NET projects, see .82172195-AA00-4FD3-BDD7-1037A5B8992A
Building, deploying, and running the sample
Build a Windows 8.x Store app project as you would build a standard project. (On the menu bar, choose Build, Build Solution). The build step compiles the code and also packages it for use as a Windows 8.x Store app.
After you build the project, you must deploy it. (On the menu bar, choose Build, Deploy Solution). Visual Studio also deploys the project when you run the app from the debugger.
After you deploy the project, pick the Bing Maps Trip Optimizer tile to run the app. Alternatively, from Visual Studio, on the menu bar, choose Debug, Start Debugging. Make sure that TripOptimizerWebApp is the startup project.
Note
A Bing Maps Key is required to run this sample. For information about how to get a Bing Maps Key, see .1cc82ed6-1613-4d64-a0e6-0d9fdca107dc
Application workflow
Here's the workflow of the app.
- Enter up to 25 locations for the trip. The first entry specifies both the start and end location.
Tip
You can select Parks Demo or Delivery Demo to populate the locations area with predefined values.
Select the method of travel (driving or walking), the distance unit (miles or kilometers), and the optimization method (minimize distance, minimize time, or avoid traffic).
If you want to, specify the inputs to the optimization algorithm and whether to use parallel computation. Parallel computation is enabled by default.
Note
The Advanced Options section is included as a learning tool for developers. These options are not intended to be part of an app.
Choose Get Directions to start the process. The JavaScript part of the app passes the locations and options to the C++ Windows Runtime component. The C++ component performs these steps:
Use the Bing Maps Representational State Transfer (REST) services to retrieve the latitude and longitude of each location. As part of the response, Bing Maps includes all possibilities that match the location string.
For all locations that have more than one possibility, display all possibilities in the UI and return to step 1.
Use the Bing Maps REST services to retrieve the distance (either driving or walking) from every location to every other location. This step uses the latitude and longitude values that were obtained in step a.
Compute the optimized route among all locations and pass the route to the JavaScript part of the app.
The HTML/JavaScript part displays step-by-step travel directions and uses the Bing Maps AJAX control to display the optimized route.
You can interact with the map. When you choose a step or location from the travel directions, the AJAX control moves to that step or location and adds a pushpin to the map.
The following illustration shows a more basic view of the workflow.
The C++ component uses the Bing Maps REST services in two phases. The first phase helps the user verify that Bing Maps has the correct locations. For example, if you specify "Pittsburgh", Bing Maps might return "Pittsburgh, PA," "Pittsburgh, ON," and "Pittsburgh, GA" as the possibilities. When ambiguities are resolved early in the process, the second phase, which retrieves the distance from every point to every other point, can run without encountering ambiguous locations.
Note
We could have performed the communication with the Bing Maps REST services in the JavaScript part of the app. We added it to the C++ component because we wanted to demonstrate how to communicate with a REST interface and parse the XML response from C++.
Next Steps
Read Using JavaScript in the Bing Maps Trip Optimizer sample for information about how JavaScript is used in the Bing Maps Trip Optimizer app.