Services

The ALKMaps Leaflet plugin also allows you take advantage of many ALKMaps services directly.

Geocode

Geocoding allows you to retrieve longitude and latitude coordinates for a given address. The geocoding service can be consumed using the L.ALKMaps.Services.geocode function. The parameters are explained in the table below.

Parameters

ParameterTypeDescription
addressObjectObject containing all the properties of the full address
  • StreetAddress
  • City
  • County
  • State
  • Zip
region[NA | EU | OC | SA | AS | AF | ME]

Default: NA
NA: North America
EU: Europe
OC: Australia
SA: South America
AF: Africa
ME: Middle East
AS: Asia
dataset[Current | PCM_EU | PCM_OC | PCM_SA |
PCM_AF | PCM_ME | PCM_IN | PCM_SE]


Default: Current
Current: NA/Current
PCM_EU: Europe
PCM_OC: Australia
PCM_SA: South America
PCM_AF: Africa
PCM_ME: Middle East
PCM_IN: India
PCM_SE: South East Asia
listSizeNumberSometimes the geocode service may return multiple results, this parameter can be used to specify how many of those results should be returned.
successFunctionFunction handles successful asynchronous service response.
failureFunctionFunction handles failed asynchronous service response.
L.ALKMaps.Services.geocode({
  address: {
    addr: "1000 Herrontown Road",
    city: "Princeton",
    state: "NJ",
    zip: "08540"
  },
  success: function(response) {
    console.log(response);
  }
});

Coords

The Coords property of the response contains an object with a Lon property and a Lat property. The coordinates returned by the previous example can be accessed from inside the success callback function in the following manner:

var geocodedLongitude = response[0].Coords.Lon; //-74.654726
var geocodedLatitude = response[0].Coords.Lat; //40.38825

Reverse Geocode

Reverse geocoding allows you to retrieve the nearest address from the given longitude and latitude coordinates. The reverse geocoding service can be consumed using the L.alk.geocode.ReverseGeocoder class. The parameters are explained in the table below.

Parameters

ParameterTypeDescription
lonLatArrayCoordinates of the location.
region[NA | EU | OC | SA | AS | AF | ME]

Default: NA
NA: North America
EU: Europe
OC: Australia
SA: South America
AF: Africa
ME: Middle East
AS: Asia
dataset[Current | PCM_EU | PCM_OC | PCM_SA |
PCM_AF | PCM_ME | PCM_IN | PCM_SE]


Default: Current
Current: NA/Current
PCM_EU: Europe
PCM_OC: Australia
PCM_SA: South America
PCM_AF: Africa
PCM_ME: Middle East
PCM_IN: India
PCM_SE: South East Asia
successFunctionFunction handles successful asynchronous service response..
failureFunctionFunction handles failed asynchronous service response.
L.ALKMaps.Services.getRoutePath({
  stops:
    "-75.339368,40.11442;-74.911539,40.159933;-74.885531,39.993483;-75.191123,39.802326",
  options: {
    region: "NA",
    dataset: "Current",
    vehicleType: "Truck",
    routingType: "Practical",
    highwayOnly: false,
    tollDiscourage: true
  },
  success: function(response) {
    console.log(response);
  }
});

Route Path

Given a list of stop coordinates and route options, the route path service will return a list of coordinates that make up the route. The service can be consumed using the L.ALKMaps.Services.getRoutePath function. The parameters are explained out in the table below.

ParameterTypeDescription
stopsstringA string containing each of the route’s stop coordinates in the following format: “lon,lat;…;lon,lat”
optionsobjectSee routing layer page for a list of available options.
successfunctionFunction handles successful asynchronous service response.
failurefunctionFunction handles failed asynchronous service response.
L.ALKMaps.Services.getRoutePath({
  stops:
    "-75.339368,40.11442;-74.911539,40.159933;-74.885531,39.993483;-75.191123,39.802326",
  options: {
    region: "NA",
    dataset: "Current",
    vehicleType: "Truck",
    routingType: "Practical",
    highwayOnly: false,
    tollDiscourage: true
  },
  success: function(response) {
    console.log(response);
  }
});

Reports

The reports service allows you to retrieve several different types of reports for any given route. The reports service can be consumed using the alk.service.RouteReportsService function. The parameters for this function are explained in the table below.

ParameterTypeDescription
coordsArray of decimal pairsAn array of coordinate pair arrays.
optionsObjectSee routing layer page for a list of available options.
reportOptionsObject
ParameterType/ValuesDescription
type[Mileage | Directions | Detail | State |
CalcMiles | LeastCost | Geotunnel]
Comma-separated list of requested report types.
format[json | html]Default: json
The format of the report returned with the route.
successFunctionFunction handles successful asynchronous service response.
failureFunctionFunction handles failed asynchronous service response.
L.ALKMaps.Services.getReports({
  coords: [[-74.655522, 40.367494], [-74.6484, 40.40347]],
  options: {
    region: "NA",
    dataset: "Current",
    vehicleType: "Truck",
    routingType: "Practical",
    highwayOnly: false,
    tollDiscourage: true
  },
  reportOptions: {
    type: "Directions,Mileage",
    format: "html"
  },
  success: function(response) {
    document.getElementById("directionsDiv").appendChild(response.Directions);
  }
});

When you choose the html format for your reports, all the formatting and styling of the report is done for you. To display a report all you need to do is append it to an existing div element in your document as shown in the example code above. For example, a directions report for a simple route should resemble the report seen in the image below.

Directions Report

Last updated November 8, 2019.