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 alk.geocode.Geocoder class. The parameters are explained in the table below.

ParameterTypeDescription
addressObjectObject containing all the properties of the full address
addr - Street Address
city - City
state - State
zip - Postal code
region - Region [NA / EU / OC / SA / AS / AF / ME]
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.
var geocoder = new alk.geocode.Geocoder();

geocoder.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 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.
var reverseGeocoder = new alk.geocode.ReverseGeocoder();

reverseGeocoder.reverseGeocode({
  lonLat: [-122.31693, 47.60784],
  region: "NA",
  dataset: "Current",
  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.

var reportService = new alk.service.RouteReportsService();
reportService.get(
  {
    reports: [alk.val.Report.Directions],
    stops: [[-74.655522, 40.367494], [-74.6484, 40.40347]]
  },
  function(response) {
    console.log(response);
  }
);