MapQuest-GL.js

mqgl.Service.directions

The direction object for retrieving routes, optimized routes, alternate routes, drag routes, route shape, route matrix, and find link id from the directions web service.

Methods

mqgl.Service.directions.route(options)

Get directions between two addresses. Refer to the Directions Route API for more information.

Syntax

var services = new mqgl.Service('KEY');

services.directions.route({
  locations: [
    '2001 Blake St, Denver, CO',
    '1555 Blake St, Denver, CO'
  ]
}).then(response => console.log(response));

Parameters

Return Value

A Promise, containing the directions response object.

Example

Loading...

mqgl.Service.directions.alternateRoutes(options)

Get directions with alternate routes. Refer to the Alternate Routes API for more information.

Syntax

var services = new mqgl.Service('KEY');

services.directions.alternateRoutes({
  locations: [
    'Denver, CO',
    'Boulder, CO'
  ]
}).then(response => console.log(response));

Parameters

Return Value

A Promise, containing the Alternate Routes response object.

Example

Loading...

mqgl.Service.directions.optimizedRoute(options)

Get directions with an optimized route. Refer to the Optimized Route API for more information.

Syntax

var services = new mqgl.Service('KEY');

services.directions.optimizedRoute({
  locations: [
    'Monroe, LA',
    'Shreveport, LA',
    'Minden, LA',
    'Ruston, LA'
  ]
}).then(response => console.log(response));

Parameters

Return Value

A Promise, containing the Optimized Route response object.

Example

Loading...

mqgl.Service.directions.routeMatrix(options)

Get distances and driving times between a set of points. Refer to the Route Matrix API for more information.

Syntax

var services = new mqgl.Service('KEY');

services.directions.routeMatrix({
  locations: [
    'Denver, CO',
    'Westminster, CO',
    'Boulder, CO'
  ],
  options: {
    'allToAll': true
  }
}).then(response => console.log(response));

Parameters

Return Value

A Promise, containing the Route Matrix response object.

Example

Loading...

mqgl.Service.directions.dragRoute(options)

Drag Route requests allow a route to be recalculated "on the fly" by quickly inserting a new location into the list of existing locations. Refer to the Drag Route API for more information.

Syntax

var services = new mqgl.Service('KEY');

services.directions.dragRoute({
  "mapState": {
    "center": {
      "lat": 40.47683477496205,
      "lng": -76.46776167187544
    },
    "width": 400,
    "height": 300,
    "scale": 1733371
  },
  "locations": [
    {
      "linkId": 26982167,
      "latLng": {
        "lng": -77.793263,
        "lat": 40.777703
      },
      "dragPoint": false
    },
    {
      "latLng": {
        "lng": -76.85228315623507,
        "lat": 40.296919938790374
      },
      "dragPoint": true
    },
    {
      "linkId": 37654138,
      "latLng": {
        "lng": -75.16562,
        "lat": 39.951061
      },
      "dragPoint": false
    }
  ]
}).then(response => console.log(response));

Parameters

Return Value

A Promise, containing the Drag Route response object.

Example

Loading...

mqgl.Service.directions.routeShape(options)

The Route Shape API takes a session ID and returns the Route Shape information for the route. Refer to the Route Shape API for more information. Note that session ID's expire after 30 minutes.

Syntax

var services = new mqgl.Service('KEY');

services.directions.findLinkId({
  'sessionId': 'SESSION_ID',
  'fullShape': true
}).then(response => console.log(response));

Parameters

Return Value

A Promise, containing the Route Shape API response object.

Example

{
  "route": {
    "boundingBox": {
      "ul": {
        "lng": -77.793266,
        "lat": 40.798587
      },
      "lr": {
        "lng": -76.729667,
        "lat": 40.203571
      }
    },
    "shape": {
      "maneuverIndexes": [
        0,
        2,
        4,
        6,
        8,
        10,
        12,
        14,
        16,
        18,
        20,
        22,
        52,
        54,
        55
      ],
      "shapePoints": [
        40.203735,
        -76.729667,
        40.203617,
        -76.729705,
        40.203617,
        -76.729705,
        40.203571,
        -76.733085,
        40.203571,
        -76.733085,
        40.212993,
        -76.735542,
        40.212993,
        -76.735542,
        40.222515,
        -76.753242,
        40.222515,
        -76.753242,
        40.222,
        -76.754974,
        40.222,
        -76.754974,
        40.227867,
        -76.757873,
        40.227867,
        -76.757873,
        40.227539,
        -76.761886,
        40.227539,
        -76.761886,
        40.221908,
        -76.783859,
        40.221908,
        -76.783859,
        40.249027,
        -76.812561,
        40.249027,
        -76.812561,
        40.304954,
        -76.83039,
        40.304954,
        -76.83039,
        40.301498,
        -76.872665,
        40.301498,
        -76.872665,
        40.364498,
        -76.92881,
        40.368495,
        -76.981414,
        40.382682,
        -77.016967,
        40.397239,
        -77.008132,
        40.430889,
        -77.010658,
        40.471801,
        -77.032135,
        40.480957,
        -77.049224,
        40.479011,
        -77.068656,
        40.493789,
        -77.082611,
        40.498321,
        -77.126365,
        40.526847,
        -77.134216,
        40.564601,
        -77.169754,
        40.57061,
        -77.243759,
        40.539234,
        -77.341888,
        40.556442,
        -77.362098,
        40.594371,
        -77.377586,
        40.611503,
        -77.445732,
        40.579284,
        -77.551391,
        40.622348,
        -77.580848,
        40.653442,
        -77.583488,
        40.668922,
        -77.604171,
        40.683479,
        -77.607658,
        40.703529,
        -77.597267,
        40.727935,
        -77.604621,
        40.732955,
        -77.63565,
        40.760101,
        -77.614212,
        40.794662,
        -77.625228,
        40.798587,
        -77.656425,
        40.779037,
        -77.771057,
        40.779037,
        -77.771057,
        40.778633,
        -77.793205,
        40.778633,
        -77.793205,
        40.777702,
        -77.793266
      ],
      "legIndexes": [
        0,
        56
      ]
    },
    "routeError": {
      "message": "",
      "errorCode": -400
    },
    "options": {
      "mustAvoidLinkIds": [],
      "drivingStyle": 2,
      "countryBoundaryDisplay": true,
      "generalize": -1,
      "narrativeType": "text",
      "locale": "en_US",
      "avoidTimedConditions": false,
      "destinationManeuverDisplay": true,
      "enhancedNarrative": false,
      "filterZoneFactor": -1,
      "timeType": 0,
      "maxWalkingDistance": -1,
      "routeType": "FASTEST",
      "transferPenalty": -1,
      "stateBoundaryDisplay": true,
      "walkingSpeed": -1,
      "maxLinkId": 0,
      "arteryWeights": [],
      "tryAvoidLinkIds": [],
      "unit": "M",
      "routeNumber": 0,
      "shapeFormat": "raw",
      "maneuverPenalty": -1,
      "useTraffic": false,
      "returnLinkDirections": false,
      "avoidTripIds": [],
      "manmaps": "true",
      "highwayEfficiency": 22,
      "sideOfStreetDisplay": true,
      "cyclingRoadFactor": 1,
      "urbanAvoidFactor": -1
    }
  },
  "info": {
    "copyright": {
      "text": "© 2017 MapQuest, Inc.",
      "imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
      "imageAltText": "© 2017 MapQuest, Inc."
    },
    "statuscode": 0,
    "messages": []
  }
}