Routing API examples

We provide some different language examples to get started with the API. In order to the try the examples below, request an API-KEY and replace in the code when required.

  1. Routing Ocean
  2. Routing Intermodal

Route from 2 water points

Requesting a simple route between 2 points. See image for the returned route:
Selection_067

Complete example that is requesting a route without any specific parameters:

// initialisation with your API KEY
$MY_API_KEY_HERE = 'YOUR-API-KEY-HERE';

// base url for the subsequent requests
$base_url = "https://api.searoutes.com/gr/route";

// send the API key in the request
$curl_headers = array(
    'accept: application/json ',
    'x-api-key: '.$MY_API_KEY_HERE,
);

// initialize curl and pass the api key in the header
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, $curl_headers);

// curl has been initialised and ready to be used

// simple route from point A to point B that is using the default options
$from_point = 'lon:9.1lat:42.5';
$to_point = 'lon:-6.8lat:46.8';

$url = $base_url."/".$from_point."/".$to_point;
curl_setopt($curl, CURLOPT_URL, $url);

$route = curl_exec($curl);

curl_close($curl);
print ($route);
   

public static void main(String[] args) throws Exception {
  // initialisation with your API KEY
  final String MY_API_KEY_HERE = "YOUR-API-KEY-HERE";

  // base url for the subsequent requests
  final String base_url = "https://api.searoutes.com/gr/route";

  // simple route from point A to point B that is using the default options
  final String from_point = "lon:9.1lat:42.5";
  final String to_point = "lon:-6.8lat:46.8";

  final String url = base_url + '/' + from_point + '/' + to_point;

  HttpsURLConnection con = (HttpsURLConnection) new URL(url).openConnection();

  // send the API key in the request
  con.setRequestProperty("x-api-key", MY_API_KEY_HERE);
  con.setRequestProperty("accept", "application/json");

  ByteArrayOutputStream baos = new ByteArrayOutputStream();

  byte[] buffer = new byte[4096];
  InputStream is = con.getInputStream();
  for (int nRead = is.read(buffer); nRead != -1; nRead = is.read(buffer)) {
    baos.write(buffer, 0, nRead);
  }
  is.close();

  System.out.println(new String(baos.toByteArray(), "UTF8"));
}
   

# Python 3
import requests

# initialisation with your API KEY
MY_API_KEY_HERE = 'YOUR-API-KEY-HERE'

# base url for the subsequent requests
base_url = "https://api.searoutes.com/gr/route"

# custom headers with our API key
request_headers = {
    'accept': 'application/json',
    'x-api-key': MY_API_KEY_HERE
}

# simple route to point B that is using the default options
from_point = 'lon:9.1lat:42.5'
to_point = 'lon:-6.8lat:46.8'

url = '/'.join((base_url, from_point, to_point))

response = requests.get(url, headers=request_headers)
print (response.text)

   

The returned object will be a JSON object that contains the details about the route requested. For example requesting the route above will return [truncated for clarity]:

{
  "@type": "graphRoute,
  "getRouteJson": [
    {
      "journeytime": 192635315,
      "eta": 192635315
      "routepoints": [
        {
          "lon": 8.7,
          "lat": 42.55,
          "trackDistance": 0
        },
        {
          "lon": 8.550000190734863,
          "lat": 42.59749984741211,
          "trackDistance": 7.2193095432128525
        },
        {
          "lon": 8.430832862854004,
          "lat": 42.579166412353516,
          "trackDistance": 12.600777879411474
        },
        {
          "lon": 8.247958183288574,
          "lat": 42.595252990722656,
          "trackDistance": 20.742163820007427
        },
        {
          "lon": 8.068178176879883,
          "lat": 42.509403228759766,
          "trackDistance": 30.21821289829222
        }
        // -- snip --
      ]
    }
  ]
}

Requesting a simple route between 2 points that is avoid the inland usage. See image for the returned route:
route_without_inland

// route that is avoid inland usage [we are explicitly passing a specific parameter]
$requestParameters = array (
    'avoidInland' => "true"
);

// create the new url with the specific parameter
$url = $base_url."/".$from_point."/".$to_point . "?" . http_build_query($requestParameters, '', "&");
   

// route that is avoid inland usage [we are explicitly passing a specific parameter]
final String url = base_url + '/' + from_point + '/' + to_point + "?avoidInland=true";
//
   

# route that is avoid inland usage [we are explicitly passing a specific parameter]
request_params = {'avoidInland': 'true'}

# create the new url with the specific parameter
response = requests.get(url, headers=request_headers, params=request_params)
   

Requesting a simple route between 2 points that is avoid passing on SECA zones. See image for the returned route:
routing_SECA_zones

// route that is avoid SECA zones [we are passing a parameter]
$from_point = 'lon:-4.5lat:49.6';
$to_point = 'lon:48lat:67.9';
$requestParameters = array (
    'avoidSeca' => "true"
);

// create the new url with the specific parameter
$url = $base_url."/".$from_point."/".$to_point . "?" . http_build_query($requestParameters, '', "&");
   

// route that is avoid SECA zones [are are passing a parameter]
final String from_point = "lon:-4.5lat:49.6";
final String to_point = "lon:48lat:67.9";

final String url = base_url + '/' + from_point + '/' + to_point + "?avoidSeca=true";
//
   

# route that is avoid SECA zones [we are passing a parameter]
from_point = 'lon:-4.5lat:49.6'
to_point = 'lon:48lat:67.9'
request_params = {'avoidSeca': 'true'}

# create the new url with the specific parameter
url = '/'.join((base_url, from_point, to_point))
   

Intermodal route between 2 points

Back to the table of contents

Requesting a route between 2 cities [Dublin to Berlin]. See image for the returned route:
urban_route_1

Complete example that is requesting an intermodal route without any specific parameters:

// initialisation with your API KEY
$MY_API_KEY_HERE = 'YOUR-API-KEY-HERE';
// base url for the subsequent requests
$base_url = "https://api.searoutes.com/intermodal/route";
// send the API key in the request
$curl_headers = array(
    'accept: application/json ',
    'x-api-key: '.$MY_API_KEY_HERE,
);
// initialize curl and pass the api key in the header
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, $curl_headers);
// curl has been initialised and ready to be used
// simple route from point A to point B that is using the default options
$from_point = 'lon:-6.24lat:53.33';
$to_point = 'lon:13.4lat:52.5';

$url = $base_url."/".$from_point."/".$to_point;
curl_setopt($curl, CURLOPT_URL, $url);
$route = curl_exec($curl);
curl_close($curl);
print ($route);
     

// initialisation with your API KEY
final String MY_API_KEY_HERE = "YOUR-API-KEY-HERE";
// base url for the subsequent requests
final String base_url = "https://api.searoutes.com/intermodal/route";
// simple route from point A to point B that is using the default options
final String from_point = "lon:9.1lat:42.5";
final String to_point = "lon:-6.8lat:46.8";
final String url = base_url + '/' + from_point + '/' + to_point;
HttpsURLConnection con = (HttpsURLConnection) new URL(url).openConnection();
// send the API key in the request
con.setRequestProperty("x-api-key", MY_API_KEY_HERE);
con.setRequestProperty("accept", "application/json");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
InputStream is = con.getInputStream();
for (int nRead = is.read(buffer); nRead != -1; nRead = is.read(buffer)) {
    baos.write(buffer, 0, nRead);
}
is.close();
System.out.println(new String(baos.toByteArray(), "UTF8"));
}
     

# Python 3
import requests

# initialisation with your API KEY
MY_API_KEY_HERE = 'YOUR-API-KEY-HERE'


# base url for the subsequent requests
base_url = "https://api.searoutes.com/intermodal/route"

# custom headers with our API key
request_headers = {
    'accept': 'application/json',
    'x-api-key': MY_API_KEY_HERE
}

# simple route from point A to point B that is using the default options
from_point = 'lon:-6.24lat:53.33'
to_point = 'lon:13.4lat:52.5'


# create the new url with the specific parameter
url = '/'.join((base_url, from_point, to_point))
response = requests.get(url, headers=request_headers)
print (response.text)


     

The returned object will be a JSON object that contains the details about the route requested. For example requesting the route above will return [truncated for clarity]:

  {
    "@type": "graphRoute",
    "getRouteJson": [
      {
        "journeytime": 195410147,
        "eta": 195410147,
        "routepoints": [
          {
            "lon": -6.24,
            "lat": 53.33,
            "trackDistance": 0,
            "name": "Dublin",
            "locode": "IEDUB",
            "clazz": 102
          },
          {
            "lon": -6.1548871994018555,
            "lat": 53.343929290771484,
            "trackDistance": 3.163888719917506,
            "routingAreaId": 40
          },
          {
            "lon": -6.122100353240967,
            "lat": 53.34146499633789,
            "trackDistance": 4.348448727870446,
            "routingAreaId": 40
          },
          {
            "lon": -6.0766143798828125,
            "lat": 53.32109451293945,
            "trackDistance": 6.387001037074569,
            "routingAreaId": 40
          },
          {
            "lon": -6.033897399902344,
            "lat": 53.29395294189453,
            "trackDistance": 8.62400535923567,
            "routingAreaId": 40
          },
          {
            "lon": -6.01751184463501,
            "lat": 53.266868591308594,
            "trackDistance": 10.353264393846633,
            "routingAreaId": 40
          },
          {
            "lon": -5.98298978805542,
            "lat": 53.184146881103516,
            "trackDistance": 15.47260043254414,
            "routingAreaId": 40
          },
          {
            "lon": -5.958453178405762,
            "lat": 53.13339614868164,
            "trackDistance": 18.64510468690199,
            "routingAreaId": 40
          },
          {
            "lon": -5.954138278961182,
            "lat": 53.09218215942383,
            "trackDistance": 21.1244970925778,
            "routingAreaId": 40
          }
        // -- snip --
      ]
    }
  ]
}

For more information about the possible parameters that can be used please refer to the Routing API Documentation.