Tide API Examples

  1. Get information about the tides in given area
  2. Get information on a tide station by name

Get the information about tides in a given area

Example of getting information about a tide by specifying the bounding box of the area. The start end of the time window is passed as parameter:

// 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/ts/tide/byarea";
// 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 (
    'lat1' => 54.46,
    'lon1' => 7.62,
    'lat2' => 53.97,
    'lon2' => 8.65,
    'begin' => 1469578000,
    'end' => 1469660400,
    'interval' => 3600
);
// create the new url with the specific parameter
$url = $base_url . "?" . http_build_query($requestParameters, '', "&");
curl_setopt($curl, CURLOPT_URL, $url);
$response = curl_exec($curl);
curl_close($curl);
print ($response);
     

// 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/ts/tide/byarea";
// provide a search query
final String url = base_url +  "?lat1=54.46&lon1=7.62&lat2=53.97&lon2=8.65&begin=1469578000&end=1469660400&interval=3600";
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/ts/tide/byarea"

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

# search term
request_params = {
  'lat1' : 54.46,
  'lon1' : 7.62,
  'lat2' : 53.97,
  'lon2' : 8.65,
  'begin' : 1469578000,
  'end' : 1469660400,
  'interval' : 3600
  }

# 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 object that contains the information about the requested tide area. For example the request above will return:

{
  "station_name": "Blauort, Germany",
  "water_level": [
    {
      "unixtime": 1469577960,
      "value": 0.841882
    },
    {
      "unixtime": 1469581560,
      "value": 1.788776
    },
    {
      "unixtime": 1469585160,
      "value": 2.775965
    },
    {
      "unixtime": 1469588760,
      "value": 3.328004
    },
    {
      "unixtime": 1469592360,
      "value": 3.546169
    },
    {
      "unixtime": 1469595960,
      "value": 3.529975
    },
    {
      "unixtime": 1469599560,
      "value": 3.196723
    },
    {
      "unixtime": 1469603160,
      "value": 2.559809
    },
    {
      "unixtime": 1469606760,
      "value": 1.688138
    },
    {
      "unixtime": 1469610360,
      "value": 0.874989
    },
    {
      "unixtime": 1469613960,
      "value": 0.475728
    },
    {
      "unixtime": 1469617560,
      "value": 0.471734
    },
    {
      "unixtime": 1469621160,
      "value": 0.786757
    },
    {
      "unixtime": 1469624760,
      "value": 1.609338
    },
    {
      "unixtime": 1469628360,
      "value": 2.682864
    },
    {
      "unixtime": 1469631960,
      "value": 3.47757
    },
    {
      "unixtime": 1469635560,
      "value": 3.867294
    },
    {
      "unixtime": 1469639160,
      "value": 3.952357
    },
    {
      "unixtime": 1469642760,
      "value": 3.692936
    },
    {
      "unixtime": 1469646360,
      "value": 3.142311
    },
    {
      "unixtime": 1469649960,
      "value": 2.348264
    },
    {
      "unixtime": 1469653560,
      "value": 1.40339
    },
    {
      "unixtime": 1469657160,
      "value": 0.665059
    }
  ],
  "tides": [
    {
      "unixtime": 1469593980,
      "value": 3.57,
      "type": "high"
    },
    {
      "unixtime": 1469615760,
      "value": 0.44,
      "type": "low"
    },
    {
      "unixtime": 1469638260,
      "value": 3.96,
      "type": "high"
    }
  ],
  "sun": [
    {
      "unixtime": 1469590200,
      "type": "sunrise"
    },
    {
      "unixtime": 1469647920,
      "type": "sunset"
    }
  ],
  "moon": [
    {
      "unixtime": 1469623920,
      "type": "moonset"
    },
    {
      "unixtime": 1469660280,
      "type": "moonrise"
    }
  ],
  "next_peak": {
    "unixtime": 1469593980,
    "value": 3.57
  }
}

Get information for a tide station by its name

Back to the table of contents

Example of getting the information about a tide station named hamburg within 2 timestamps with a resolution of one hour

// 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/ts/tide/byname";
// 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 parameters
$requestParameters = array(
      'name' => 'hamburg',
      'begin' => 1469578000,
      'end' => 1469660400,
      'interval' => 3600
);
// create the new url with the specific parameter
$url = $base_url . "?" . http_build_query($requestParameters, '', "&");
curl_setopt($curl, CURLOPT_URL, $url);
$response = curl_exec($curl);
curl_close($curl);
print ($response);
     

// 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/ts/tide/byname";
// provide a search query
final String url = base_url +  "?name=hamburg&begin=1469578000&end=1469660400&interval=3600";
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/ts/tide/byname"

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

# search terms

request_params = {
  'name' : 'hamburg',
  'begin' : 1469578000,
  'end' : 1469660400,
  'interval' : 3600
  }

# 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 with all the tides. For example the request above will return:

{
  "station_name": "Hamburg",
  "water_level": [
    {
      "unixtime": 1469577960,
      "value": 1.800802
    },
    {
      "unixtime": 1469581560,
      "value": 1.206614
    },
    {
      "unixtime": 1469585160,
      "value": 0.595076
    },
    {
      "unixtime": 1469588760,
      "value": 0.14367
    },
    {
      "unixtime": 1469592360,
      "value": 0.592285
    },
    {
      "unixtime": 1469595960,
      "value": 1.761175
    },
    {
      "unixtime": 1469599560,
      "value": 2.750911
    },
    {
      "unixtime": 1469603160,
      "value": 3.255342
    },
    {
      "unixtime": 1469606760,
      "value": 3.59479
    },
    {
      "unixtime": 1469610360,
      "value": 3.636274
    },
    {
      "unixtime": 1469613960,
      "value": 3.15105
    },
    {
      "unixtime": 1469617560,
      "value": 2.409361
    },
    {
      "unixtime": 1469621160,
      "value": 1.77809
    },
    {
      "unixtime": 1469624760,
      "value": 1.282332
    },
    {
      "unixtime": 1469628360,
      "value": 0.736178
    },
    {
      "unixtime": 1469631960,
      "value": 0.216161
    },
    {
      "unixtime": 1469635560,
      "value": 0.440222
    },
    {
      "unixtime": 1469639160,
      "value": 1.533246
    },
    {
      "unixtime": 1469642760,
      "value": 2.68848
    },
    {
      "unixtime": 1469646360,
      "value": 3.460099
    },
    {
      "unixtime": 1469649960,
      "value": 3.89775
    },
    {
      "unixtime": 1469653560,
      "value": 4.08517
    },
    {
      "unixtime": 1469657160,
      "value": 3.718042
    }
  ],
  "tides": [
    {
      "unixtime": 1469589180,
      "value": 0.14,
      "type": "low"
    },
    {
      "unixtime": 1469608860,
      "value": 3.69,
      "type": "high"
    },
    {
      "unixtime": 1469633100,
      "value": 0.17,
      "type": "low"
    },
    {
      "unixtime": 1469653020,
      "value": 4.09,
      "type": "high"
    }
  ],
  "sun": [
    {
      "unixtime": 1469590020,
      "type": "sunrise"
    },
    {
      "unixtime": 1469647440,
      "type": "sunset"
    }
  ],
  "moon": [
    {
      "unixtime": 1469623500,
      "type": "moonset"
    },
    {
      "unixtime": 1469660040,
      "type": "moonrise"
    }
  ],
  "next_peak": {
    "unixtime": 1469608860,
    "value": 3.69
  }
}

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