Geolocation API examples

This api is used to get locations of ports and shipyards

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. Find ports
  2. Find shipyards

Find ports

Get the coordinates about entities [ports or shipyards] by a partial search string.

Get list of ports starting with the string hamburg:

// 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/geocoder/pois/ports";
// 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

// define our search parameter
$requestParameters = array (
    'string' => "hamburg"
);
// create the new url with the specific parameter
$url = $base_url . "?" . http_build_query($requestParameters, '', "&");
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/geocoder/pois/ports";
// provide a search query
final String url = base_url +  "?string=hamburg";
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/geocoder/pois/ports"

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

 # search term
 request_params = {'string': 'hamburg'}

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

The returned object will be a JSON array that contains the list of matched ports. For example the request above will return:

[
  {
    "country": "DE",
    "id": 4294967298,
    "lat": 53.519272,
    "locode": "DEHAM",
    "lon": 9.93855,
    "name": "Hamburg",
    "ref": 2,
    "type": "port"
  },
  {
    "id": 4294974336,
    "lat": 58.551845,
    "locode": "SEHBO",
    "lon": 11.268235,
    "name": "HAMBURGON",
    "ref": 7040,
    "type": "port"
  }
]

Find shipyards

Back to the table of contents

Get list of shipyards starting with the string hamburg:

// 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/geocoder/pois/shipyards";
// 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

// define our search parameter
$requestParameters = array (
    'string' => "hamburg"
);
// create the new url with the specific parameter
$url = $base_url . "?" . http_build_query($requestParameters, '', "&");
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/geocoder/pois/shipyards";
// provide a search query
final String url = base_url +  "?string=hamburg";
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/geocoder/pois/shipyards"

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

# search term
request_params = {'string': 'hamburg'}

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

The returned object will be a JSON array that contains the list of matched shipyards. For example the request above will return:

[
  {
    "country": "DE",
    "id": 34359745304,
    "lat": 53.53908324183746,
    "locode": "DEHAM",
    "lon": 9.959964752197266,
    "name": "BLOHM & VOSS  GMBH",
    "ref": 6936,
    "type": "shipyard"
  },
  {
    "country": "DE",
    "id": 34359744020,
    "lat": 53.535187405008756,
    "locode": "DEHAM",
    "lon": 9.973526000976562,
    "name": "NORDERWERFT REPAIR GMBH",
    "ref": 5652,
    "type": "shipyard"
  },
  {
    "country": "DE",
    "id": 34359743994,
    "lat": 53.53253358784738,
    "locode": "DEHAM",
    "lon": 9.786299611232547,
    "name": "PELLA SIETAS",
    "ref": 5626,
    "type": "shipyard"
  }
]

For more information about this API please refer to the Geocoder API Documentation.