Skip to main content
Guides

Route Weather

Estimated reading time: 23 minutes

In this guide you will learn how to get the weather along a route, for the specific time you will be at each position along the route during navigation.

Setup

First, get an API key token, see the Getting Started guide.

Route Weather entry point

URL: https://weather.magiclaneapis.com/v1/WeatherRoute

EXAMPLE

These are complete working examples in several different languages, showing how to use the weather REST API. You can try them right now.

Linux terminal / Windows command prompt:

curl "https://weather.magiclaneapis.com/v1/WeatherRoute" -X POST -H "Content-Type: application/json" -H "Authorization: YOUR_API_KEY_TOKEN" -d @payload.json

Linux note - do not use @~/payload.json instead of @/home/user/payload.json because ~ does not resolve due to the @ ; use only relative path @payload.json or absolute path @/home/user/payload.json

where

payload.json is a text file containing the following:

complete payload.json file - coords , one or more semicolon ; separated latitude,longitude,unix_timestamp_seconds coordinate pairs - the weather will be returned for each one separately; details - 0 returns weather description and temperature (default), 1 - returns all available weather parameters.

{
"coords": "43.0, 2.0, 1699512512; 42.6, 2.5, 1699512712; 42.3, 3.111, 1699512912",
"details": 0
}

In a linux terminal you can also send the request directly from the command line, without a file, like this: (this method does not work on windows)

curl "https://weather.magiclaneapis.com/v1/WeatherRoute" -X POST -H "Content-Type: application/json" -H "Authorization: YOUR_API_KEY_TOKEN" -d \
'{
...
}'

The only difference is the added backslash after -d, and then the filename @/home/user/payload.json is replaced with the contents of the json file, starting with the next line - note that a single quote ‘ is added before the leading curly brace { and after the trailing curly brace } to enclose the file contents in single quotes - no backslashes are needed between the single quotes.

REQUEST PARAMETER DEFINITIONS

Request body schema: application/json

keyvalue
coords
(mandatory
parameter)
A list of ; (semicolon) separated latitude,longitude,unix_timestamp_seconds coordinate pairs - the weather will be returned for each separately. Example:
“43,2,1699512512;42.6,2.5,1699512712;42.3,3.1,1699512912”
Note that the unix timestamp, which is the number of seconds elapsed since 1 January 1970 at 00:00, must be in the present or future, as historical weather data is not available.
Type: string
detailsType: integer
Default value: 0
Possible values - 0:returns weather description and temperature; 1:returns all available weather parameters

RESPONSE

WeatherRoute results

Each result item is given in a JSON block as shown below.

In the above examples, 3 coordinate pairs were requested, so the result shows the weather for each of the 3 locations specified along the route at the indicated times. The coordinates are latitude, longitude (degrees). The date timestamp field is the UNIX time in seconds since 1 January 1970 at 00:00. WindDirection is in degrees, where 0 is North, 90 is East, 180 is South and 270 is West.

If details is set to 0, then the parameters block contains only Temperature ; otherwise, if details is set to 1, this block contains all parameters as shown below.

{
"Weather route": [
{
"WeatherConditions": "Light rain",
"date": 1699512512,
"daylight": "day",
"latitude": 43,
"longitude": 2,
"parameters": {
"DewPoint": 2,
"FeelsLike": 7,
"Humidity": 75,
"Pressure": 1015,
"Temperature": 8,
"UV": 0,
"WindDirection": 90,
"WindSpeed": 2
}
},
{
"WeatherConditions": "Cloudy",
"date": 1699512712,
"daylight": "day",
"latitude": 42.6,
"longitude": 2.5,
"parameters": {
"DewPoint": 1,
"FeelsLike": 7,
"Humidity": 67,
"Pressure": 1013,
"Temperature": 7,
"UV": 0,
"WindDirection": 112,
"WindSpeed": 2
}
},
{
"WeatherConditions": "Cloudy",
"date": 1699512912,
"daylight": "day",
"latitude": 42.3,
"longitude": 3.1,
"parameters": {
"DewPoint": 6,
"FeelsLike": 11,
"Humidity": 65,
"Pressure": 1013,
"Temperature": 11,
"UV": 0,
"WindDirection": 78,
"WindSpeed": 4
}
}
],
"info": {
"copyrights": [
"MagicLane"
]
},
"unit": "metric"
}