Weather API examples

  1. Weather condition for a location in a given time
  2. Weather statistics for a location
  3. Weather details for an array of locations

Get weather information for a location at a given time

Example of getting on how getting the weather condition at one give timestamp

// 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/ws/weather/real";
// 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(
  'lat' => 52.3844,
  'lon' => 4.94,
  'ts' => 1501580712
);
// 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/ws/weather/real";
// provide a search query
  final String url = base_url +  "?lat=52.3844&lon=4.94&ts=1501580712";
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/ws/weather/real"

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

# search terms
request_params = {
    'lat' : 52.3844'
    'lon' : 4.94
    'ts' : 1501580712
}

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

[
  {
    "ts_in": 1501580712,
    "lon_in": 4.94,
    "lat_in": 52.3844,
    "ts": "2017-08-01T09:00:00.000Z",
    "id": 22150281647,
    "time": "2017-08-01T09:00:00.000Z",
    "lon": 5,
    "lat": 52.5,
    "tmp2m": 19.9,
    "tmpsfc": 20.4,
    "tmax2m": 19.9,
    "tmin2m": 17.5,
    "rh2m": 63.1,
    "prmsl": 1015.1,
    "ugrd10m": 2.4,
    "vgrd10m": 1.4,
    "gustsfc": 3.5,
    "tcdc": 100,
    "apcp": 0,
    "prate": 0,
    "icecsfc": 0,
    "landsfc": 0,
    "wavehgt": 0,
    "waveprd": 0,
    "wavedir": 0,
    "geo_points": 0,
    "water_u": 0,
    "water_v": 0,
    "salinity": 0
  }
]

Get weather statistics for a location

Back to the table of contents

Example getting on how getting the weather statistics for a given location

// 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/ws/weather/stat";
// 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(
  'lat' => 52.3844',
  'lon' => 4.94
);
// 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/ws/weather/stat";
// provide a search query
  final String url = base_url +  "?lat=52.3844&lon=4.94";
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/ws/weather/stat"

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

# search terms
request_params = {
    'lat' : 52.3844'
    'lon' : 4.94
}

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

  [
    {
      "month": 1,
      "lon": 15.5,
      "lat": 38,
      "tmp2m_mean": 10.739,
      "tmp2m_max": 17.574,
      "tmp2m_min": 3.884,
      "precip_sum_month": 64.998,
      "precip_days": 11.673,
      "wind_u_mean": 1.032,
      "wind_v_mean": -0.727,
      "wavehgt_mean": 1.146,
      "wavehgt_max": 5.455,
      "waveprd_mean": 5.166,
      "wavedir_mean": 168.513,
      "sst_temp_mean": 15.159,
      "water_u_mean": -0.034,
      "water_v_mean": -0.034,
      "salinity_mean": 38.383,
      "lat_in": 38.2,
      "lon_in": 15.56
    },
    {
      "month": 2,
      "lon": 15.5,
      "lat": 38,
      "tmp2m_mean": 10.482,
      "tmp2m_max": 17.258,
      "tmp2m_min": 3.848,
      "precip_sum_month": 49.571,
      "precip_days": 10.208,
      "wind_u_mean": 1.216,
      "wind_v_mean": -0.835,
      "wavehgt_mean": 1.09,
      "wavehgt_max": 4.901,
      "waveprd_mean": 5.081,
      "wavedir_mean": 167.535,
      "sst_temp_mean": 14.481,
      "water_u_mean": -0.027,
      "water_v_mean": -0.031,
      "salinity_mean": 38.456,
      "lat_in": 38.2,
      "lon_in": 15.56
    },
    {
      "month": 3,
      "lon": 15.5,
      "lat": 38,
      "tmp2m_mean": 12.003,
      "tmp2m_max": 19.906,
      "tmp2m_min": 5.2,
      "precip_sum_month": 51.996,
      "precip_days": 9.032,
      "wind_u_mean": 1.178,
      "wind_v_mean": -0.62,
      "wavehgt_mean": 0.979,
      "wavehgt_max": 4.765,
      "waveprd_mean": 4.941,
      "wavedir_mean": 176.303,
      "sst_temp_mean": 14.463,
      "water_u_mean": -0.007,
      "water_v_mean": -0.015,
      "salinity_mean": 38.486,
      "lat_in": 38.2,
      "lon_in": 15.56
    },
    {
      "month": 4,
      "lon": 15.5,
      "lat": 38,
      "tmp2m_mean": 14.275,
      "tmp2m_max": 22.064,
      "tmp2m_min": 8.558,
      "precip_sum_month": 40.08,
      "precip_days": 8.935,
      "wind_u_mean": 0.966,
      "wind_v_mean": -0.355,
      "wavehgt_mean": 0.844,
      "wavehgt_max": 3.796,
      "waveprd_mean": 4.825,
      "wavedir_mean": 176.462,
      "sst_temp_mean": 15.325,
      "water_u_mean": 0.015,
      "water_v_mean": 0.001,
      "salinity_mean": 38.477,
      "lat_in": 38.2,
      "lon_in": 15.56
    },
    {
      "month": 5,
      "lon": 15.5,
      "lat": 38,
      "tmp2m_mean": 18.404,
      "tmp2m_max": 27.364,
      "tmp2m_min": 12.16,
      "precip_sum_month": 22.188,
      "precip_days": 5.29,
      "wind_u_mean": 0.805,
      "wind_v_mean": -0.672,
      "wavehgt_mean": 0.616,
      "wavehgt_max": 3.439,
      "waveprd_mean": 4.382,
      "wavedir_mean": 176.649,
      "sst_temp_mean": 17.86,
      "water_u_mean": 0.012,
      "water_v_mean": 0.006,
      "salinity_mean": 38.45,
      "lat_in": 38.2,
      "lon_in": 15.56
    },
    {
      "month": 6,
      "lon": 15.5,
      "lat": 38,
      "tmp2m_mean": 22.647,
      "tmp2m_max": 32.343,
      "tmp2m_min": 16.255,
      "precip_sum_month": 10.278,
      "precip_days": 2.452,
      "wind_u_mean": 1.179,
      "wind_v_mean": -1.081,
      "wavehgt_mean": 0.435,
      "wavehgt_max": 2.016,
      "waveprd_mean": 3.839,
      "wavedir_mean": 192.003,
      "sst_temp_mean": 21.587,
      "water_u_mean": 0.003,
      "water_v_mean": 0.001,
      "salinity_mean": 38.407,
      "lat_in": 38.2,
      "lon_in": 15.56
    },
    {
      "month": 7,
      "lon": 15.5,
      "lat": 38,
      "tmp2m_mean": 25.442,
      "tmp2m_max": 34.542,
      "tmp2m_min": 19.634,
      "precip_sum_month": 8.011,
      "precip_days": 2.387,
      "wind_u_mean": 1.402,
      "wind_v_mean": -1.607,
      "wavehgt_mean": 0.364,
      "wavehgt_max": 1.445,
      "waveprd_mean": 3.566,
      "wavedir_mean": 202.688,
      "sst_temp_mean": 24.649,
      "water_u_mean": -0.015,
      "water_v_mean": -0.011,
      "salinity_mean": 38.417,
      "lat_in": 38.2,
      "lon_in": 15.56
    },
    {
      "month": 8,
      "lon": 15.5,
      "lat": 38,
      "tmp2m_mean": 25.857,
      "tmp2m_max": 34.328,
      "tmp2m_min": 20.583,
      "precip_sum_month": 12.762,
      "precip_days": 2.516,
      "wind_u_mean": 1.276,
      "wind_v_mean": -1.398,
      "wavehgt_mean": 0.364,
      "wavehgt_max": 1.831,
      "waveprd_mean": 3.553,
      "wavedir_mean": 194.42,
      "sst_temp_mean": 26.085,
      "water_u_mean": -0.03,
      "water_v_mean": -0.026,
      "salinity_mean": 38.454,
      "lat_in": 38.2,
      "lon_in": 15.56
    },
    {
      "month": 9,
      "lon": 15.5,
      "lat": 38,
      "tmp2m_mean": 22.773,
      "tmp2m_max": 30.955,
      "tmp2m_min": 17.201,
      "precip_sum_month": 48.879,
      "precip_days": 8.645,
      "wind_u_mean": 0.804,
      "wind_v_mean": -0.682,
      "wavehgt_mean": 0.518,
      "wavehgt_max": 2.267,
      "waveprd_mean": 4.03,
      "wavedir_mean": 164.497,
      "sst_temp_mean": 24.861,
      "water_u_mean": -0.021,
      "water_v_mean": -0.021,
      "salinity_mean": 38.426,
      "lat_in": 38.2,
      "lon_in": 15.56
    },
    {
      "month": 10,
      "lon": 15.5,
      "lat": 38,
      "tmp2m_mean": 19.328,
      "tmp2m_max": 26.687,
      "tmp2m_min": 13.381,
      "precip_sum_month": 58.111,
      "precip_days": 10.258,
      "wind_u_mean": 0.51,
      "wind_v_mean": -0.217,
      "wavehgt_mean": 0.703,
      "wavehgt_max": 3.257,
      "waveprd_mean": 4.473,
      "wavedir_mean": 148.758,
      "sst_temp_mean": 22.503,
      "water_u_mean": -0.027,
      "water_v_mean": -0.025,
      "salinity_mean": 38.34,
      "lat_in": 38.2,
      "lon_in": 15.56
    },
    {
      "month": 11,
      "lon": 15.5,
      "lat": 38,
      "tmp2m_mean": 15.194,
      "tmp2m_max": 21.787,
      "tmp2m_min": 8.365,
      "precip_sum_month": 63.438,
      "precip_days": 11.29,
      "wind_u_mean": 0.85,
      "wind_v_mean": 0.007,
      "wavehgt_mean": 1.018,
      "wavehgt_max": 4.153,
      "waveprd_mean": 5.009,
      "wavedir_mean": 166.288,
      "sst_temp_mean": 19.611,
      "water_u_mean": -0.033,
      "water_v_mean": -0.035,
      "salinity_mean": 38.335,
      "lat_in": 38.2,
      "lon_in": 15.56
    },
    {
      "month": 12,
      "lon": 15.5,
      "lat": 38,
      "tmp2m_mean": 12.023,
      "tmp2m_max": 19.175,
      "tmp2m_min": 5.06,
      "precip_sum_month": 76.833,
      "precip_days": 13.387,
      "wind_u_mean": 1.131,
      "wind_v_mean": -0.375,
      "wavehgt_mean": 1.184,
      "wavehgt_max": 5.739,
      "waveprd_mean": 5.266,
      "wavedir_mean": 175.166,
      "sst_temp_mean": 16.769,
      "water_u_mean": -0.038,
      "water_v_mean": -0.038,
      "salinity_mean": 38.38,
      "lat_in": 38.2,
      "lon_in": 15.56
    }
  ]

Weather details for an array of locations

Back to the table of contents

Example getting weather data for an array of locations

// initialisation with your API KEY
$MY_API_KEY_HERE = 'YOUR-API-KEY-HERE';
$base_url = "https://api.searoutes.com/ws/weather/track";
// send the API key in the request
$curl_headers = array(
    'accept: application/json',
    'Content-Type: application/json',
    'x-Api-key: '.$MY_API_KEY_HERE,
);
// initialize curl and pass the Api key in the header
$curl = curl_init();

// define our search parameters
$requestParameters = array(
    'speed' => 15,
    'departure' => 1500249900
);
$postData = array(
    'routepoints' =>
        array(
            array(
                'lon' => 9.9000000000000004,
                'lat' => 53.5,
                'ts' => 1499562200,
            ),
            array(
                'lon' => 9.9130830764770508,
                'lat' => 53.532833099365234,
                'ts' => 1499565700,
            ),
            array(
                'lon' => 9.9016208648681641,
                'lat' => 53.539619445800781,
                'ts' => 1499569200,
            ),
            array(
                'lon' => 9.9011907577514648,
                'lat' => 53.541893005371094,
                'ts' => 1499572700,
            ),
            array(
                'lon' => 9.8941736221313477,
                'lat' => 53.542018890380859,
                'ts' => 1499576200,
            ),
        ),
);
// create the new url with the specific parameter
$url = $base_url."?".http_build_query($requestParameters, '', "&");

//this is a post request
$postDataString = json_encode($postData);
$curl_headers[] = 'Content-Length:'.strlen($postDataString);
curl_setopt($curl, CURLOPT_HTTPHEADER, $curl_headers);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postDataString);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
$response = curl_exec($curl);
curl_close($curl);
print ($response);
     

  # 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/ws/weather/track"

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

request_params = {
    'speed': 15,
    'departure': 1500249900
}

request_body = {
    "routepoints": [
        {
          "lon": 9.9,
          "lat": 53.5,
          "ts": 1499562200
        },
        {
          "lon": 9.91308307647705,
          "lat": 53.532833099365234,
          "ts": 1499565700
        },
        {
          "lon": 9.901620864868164,
          "lat": 53.53961944580078,
          "ts": 1499569200
        },
        {
          "lon": 9.901190757751465,
          "lat": 53.541893005371094,
          "ts": 1499572700
        },
        {
          "lon": 9.894173622131348,
          "lat": 53.54201889038086,
          "ts": 1499576200
        }
    ]
}

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

     

The returned object will be a JSON array. For example the request above will return:

  [
    {
      "ts_in": 1499565700,
      "lon_in": 9.9130830764771,
      "lat_in": 53.532833099365,
      "ts": "2017-07-09T03:00:00.000Z",
      "id": 21378837657,
      "time": "2017-07-09T03:00:00.000Z",
      "lon": 10,
      "lat": 53.5,
      "tmp2m": 8.8,
      "tmpsfc": 7.4,
      "tmax2m": 10.9,
      "tmin2m": 8.8,
      "rh2m": 93.4,
      "prmsl": 1016.3,
      "ugrd10m": 0.2,
      "vgrd10m": -1.4,
      "gustsfc": 2,
      "tcdc": 24,
      "apcp": 0,
      "prate": 0,
      "icecsfc": 0,
      "landsfc": 1,
      "wavehgt": 0,
      "waveprd": 0,
      "wavedir": 0,
      "geo_points": 0,
      "water_u": 0,
      "water_v": 0,
      "salinity": 0,
      "penaltyWind": 0.7989080935087648,
      "penaltyWaves": 0.10999999999999999,
      "penaltyCurrent": 0,
      "direction": 314.8958567501408
    },
    {
      "ts_in": 1499562200,
      "lon_in": 9.9,
      "lat_in": 53.5,
      "ts": "2017-07-09T00:00:00.000Z",
      "id": 21378577737,
      "time": "2017-07-09T00:00:00.000Z",
      "lon": 10,
      "lat": 53.5,
      "tmp2m": 10.9,
      "tmpsfc": 10,
      "tmax2m": 17.5,
      "tmin2m": 10.9,
      "rh2m": 94.6,
      "prmsl": 1016.6,
      "ugrd10m": 1.3,
      "vgrd10m": -2,
      "gustsfc": 3.2,
      "tcdc": 49,
      "apcp": 0,
      "prate": 0,
      "icecsfc": 0,
      "landsfc": 1,
      "wavehgt": 0,
      "waveprd": 0,
      "wavedir": 0,
      "geo_points": 0,
      "water_u": 0,
      "water_v": 0,
      "salinity": 0,
      "penaltyWind": 0.6902786593922186,
      "penaltyWaves": -1,
      "penaltyCurrent": 0,
      "direction": 13.323961222490368
    },
    {
      "ts_in": 1499572700,
      "lon_in": 9.9011907577515,
      "lat_in": 53.541893005371,
      "ts": "2017-07-09T03:00:00.000Z",
      "id": 21378837657,
      "time": "2017-07-09T03:00:00.000Z",
      "lon": 10,
      "lat": 53.5,
      "tmp2m": 8.8,
      "tmpsfc": 7.4,
      "tmax2m": 10.9,
      "tmin2m": 8.8,
      "rh2m": 93.4,
      "prmsl": 1016.3,
      "ugrd10m": 0.2,
      "vgrd10m": -1.4,
      "gustsfc": 2,
      "tcdc": 24,
      "apcp": 0,
      "prate": 0,
      "icecsfc": 0,
      "landsfc": 1,
      "wavehgt": 0,
      "waveprd": 0,
      "wavedir": 0,
      "geo_points": 0,
      "water_u": 0,
      "water_v": 0,
      "salinity": 0,
      "penaltyWind": 0.17127799920232512,
      "penaltyWaves": 0.10999999999999999,
      "penaltyCurrent": 0,
      "direction": 271.7320305847122
    },
    {
      "ts_in": 1499576200,
      "lon_in": 9.8941736221313,
      "lat_in": 53.542018890381,
      "ts": "2017-07-09T06:00:00.000Z",
      "id": 21379097577,
      "time": "2017-07-09T06:00:00.000Z",
      "lon": 10,
      "lat": 53.5,
      "tmp2m": 13.5,
      "tmpsfc": 14.5,
      "tmax2m": 13.5,
      "tmin2m": 8.5,
      "rh2m": 78,
      "prmsl": 1016.4,
      "ugrd10m": 0,
      "vgrd10m": -0.2,
      "gustsfc": 0.5,
      "tcdc": 32,
      "apcp": 0,
      "prate": 0,
      "icecsfc": 0,
      "landsfc": 1,
      "wavehgt": 0,
      "waveprd": 0,
      "wavedir": 0,
      "geo_points": 0,
      "water_u": 0,
      "water_v": 0,
      "salinity": 0,
      "penaltyWind": 0,
      "penaltyWaves": 0.10999999999999999,
      "penaltyCurrent": 0,
      "direction": 0
    },
    {
      "ts_in": 1499569200,
      "lon_in": 9.9016208648682,
      "lat_in": 53.539619445801,
      "ts": "2017-07-09T03:00:00.000Z",
      "id": 21378837657,
      "time": "2017-07-09T03:00:00.000Z",
      "lon": 10,
      "lat": 53.5,
      "tmp2m": 8.8,
      "tmpsfc": 7.4,
      "tmax2m": 10.9,
      "tmin2m": 8.8,
      "rh2m": 93.4,
      "prmsl": 1016.3,
      "ugrd10m": 0.2,
      "vgrd10m": -1.4,
      "gustsfc": 2,
      "tcdc": 24,
      "apcp": 0,
      "prate": 0,
      "icecsfc": 0,
      "landsfc": 1,
      "wavehgt": 0,
      "waveprd": 0,
      "wavedir": 0,
      "geo_points": 0,
      "water_u": 0,
      "water_v": 0,
      "salinity": 0,
      "penaltyWind": 0.9995515021788157,
      "penaltyWaves": 0.10999999999999999,
      "penaltyCurrent": 0,
      "direction": 353.5859638244977
    }
  ]

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