Multimap logo Multimap API V1.2 JavaScript Example

Routing with Carbon Emissions *new*

This example demonstrates how to use the optional carbon emissions calculator in conjunction with the Routing module to calculate carbon emissions information. If you wish your service to contain this additional option, please contact your Multimap account manager.

If your Multimap API Routing service includes the "Carbon Emissions" option, your service can display emission-related information for a series of default vehicle types. You can also specify your own custom types of vehicles; to make use of this functionality you need to add the following parameters to your MMRoute object:

Carbon Emission parameters
Parameter Description Valid Values Example
emissions Determines whether the API should return
carbon-emission details (where they are available).
true or false
(default is false)
route.emissions = 'true';
custom_emission Defines properties for custom types of vehicles.
It is an array of object literals and each must have four
properties as listed in the table below.
array of objects route.custom_emission = [
{
'name' : 'GreenCar',
'value' : '35',
'unit' : 'mpg_imp',
'type' : 'diesel'
}
];

custom_emission properties
Properties Description Valid Values
value The fuel economy value per unit (see below). float
unit The fuel economy unit in which carbon emissions are measured:
  • miles per gallon (US gallon);
  • miles per gallon (Imperial gallon); or
  • liters per 100 kilometers.
"mpg", "mpg_imp" or "lper100km" (default is "mpg")
type The fuel type used. "diesel" or "gas" (default is "gas")
name The name or label by which you wish to denote this type of vehicle. string

What You Should See

If you view this in your browser you should see a Multimap draggable map centered on Saint James Avenue, Boston, Massachusetts, USA, at zoom factor 15.

To generate carbon-emission information for a route :

  1. Make a selection for the start and end points for your route. The latitude and longitude that correspond to your selections will be passed in as start and end 'locations' for the route.
  2. Optionally, you can also select one or two additional waypoints through which the route will travel. If selected, the latitude and longitude that correspond to your selections will be passed in as additional intermediate locations (or 'via points') for the route.
  3. You can use the fields and the drop-down lists in the Carbon Emissions control to determine the information that the web page displays:

  4. So, if you have a diesel car which consumes 20 miles per US gallon of fuel, specify Value as "20", Unit as "miles per US gallon" and Type as "Diesel".

  5. Click on the Go button to view your results.
  6. Your route is displayed, highlighted on a draggable map, with a carbon emissions table listed below it. Please note that you can can sort, filter and format the results in your list of emission elements using your own application(s).

Important note: You must display copyright and disclaimer notices when providing travel directions.

The Map

Get directions:
Carbon Emissions:
-- Custom Vehicle 1 --
Name:
Value:
Unit:
Type:
-- Custom Vehicle 2 --
Name:
Value:
Unit:
Type:
Messages and results will be placed here

The Code

There are four parts to the code below. The first is the line that links to the Multimap API. The second is an example of the HTML you must have in your page. The third is an example of the JavaScript required to implement the page. Finally, the fourth is the CSS code that you should add to your web page.

The header code

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" >
<script type="text/javascript" src="http://clients.multimap.com/API/maps/1.2/demo"></script>

The body code

Sorry, JavaScript required...
Sorry, JavaScript required...
Sorry, JavaScript required...

The JavaScript code

Sorry, JavaScript required...

The CSS code

Sorry, JavaScript required...

Note on printing

Please note that you may not be able to print a highlighted route or a polyline from the Multimap API when using a Mozilla Firefox or an Opera browser. If you encounter such a problem, please try a different browser.

For more information on the subject of Multimap API JavaScript code (including error codes for the Routing module), please read the API documentation at: http://www.multimap.com/share/documentation/api/1.2/classes/.

Back to examples.

Further Help

If you require further help with your map API implementation, please contact the Multimap Customer Support team:

Australia, Sydney + 61 (0) 2 9262 6551
Great Britain, London +44 (0)20 7632 7777
United States, Boston + 1 617 423 4510
email: info@multimap.com

For general account enquiries or further services, please contact the Multimap Sales team:

Australia, Sydney + 61 (0) 2 9262 6551
Great Britain, London +44 (0)20 7632 7800
United States, Boston + 1 617 423 4510
email: sales@multimap.com