# How to get Speed Limits extra information?

**URL:** <https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334>\
**Category:** openrouteservice\
**Created:** [March 19, 2019, 3:16pm UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334 "2019-03-19T15:16:28Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![richard.revesz](https://ask.openrouteservice.org/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@richard.revesz](https://ask.openrouteservice.org/u/richard.revesz)\
**Post date:** [March 19, 2019, 3:16pm UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334/1 "2019-03-19T15:16:28Z")

</div>

Hi,

I am looking for a way to get speed limits information of the route.

Is there a way to do that?

Here ([https://github.com/GIScience/openrouteservice-docs#routing-options](https://github.com/GIScience/openrouteservice-docs#routing-options)) I see I can get some extra info from the response, however, I have trouble creating a valid request  
I am trying to do something like this:  
[https://api.openrouteservice.org/v2/directions/driving-car?api\_key=[MY\_API\_KEY]&start=[Start\_location]&end=[End\_location]&extra\_info=“MaxSpeed”](https://api.openrouteservice.org/v2/directions/driving-car?api_key=%5BMY_API_KEY%5D&start=%5BStart_location%5D&end=%5BEnd_location%5D&extra_info=%22MaxSpeed%22) (or AvgSpeed, whatever).  
What I am doing wrong?

---

<div class="post-metadata">

**Author:** ![nils](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nils/32/6_2.png) [@nils](https://ask.openrouteservice.org/u/nils)\
**Post date:** [March 20, 2019, 6:48am UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334/2 "2019-03-20T06:48:35Z")

</div>

Hi,

we had smth like this before (avg\_speed), but that was very inaccurate. And no one was using it so we threw it out.

If you really want it, you can calculate it yourself from the response. Every `step` in the `segments` object has `duration` and `distance` specified, giving you average speeds along (mostly multiple) waypoints.

EDIT: in fact it’s still there in the response if you specify `attributes=avgspeed` I just saw. But it’s only for each segment, which is very coarse. Unit is km/h it seems.

---

<div class="post-metadata">

**Author:** ![richard.revesz](https://ask.openrouteservice.org/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@richard.revesz](https://ask.openrouteservice.org/u/richard.revesz)\
**Post date:** [March 20, 2019, 9:12am UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334/3 "2019-03-20T09:12:13Z")

</div>

Thank you Nils.  
And what is the correct syntax for specifying that?  
I am trying it (among others) like this without success:

[https://api.openrouteservice.org/v2/directions/driving-car?api\_key=[MY\_API\_KEY]&start=[Start\_location]&end=[End\_location]&attributes=avgspeed](https://api.openrouteservice.org/v2/directions/driving-car?api_key=%5BMY_API_KEY%5D&start=%5BStart_location%5D&end=%5BEnd_location%5D&attributes=avgspeed)

Your support is much appreciated!

---

<div class="post-metadata">

**Author:** ![nils](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nils/32/6_2.png) [@nils](https://ask.openrouteservice.org/u/nils)\
**Post date:** [March 20, 2019, 9:15am UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334/4 "2019-03-20T09:15:42Z")

</div>

Try our API playground:

[https://openrouteservice.org/dev/#/api-docs/v2/directions/{profile}/geojson/post](https://openrouteservice.org/dev/#/api-docs/v2/directions/%7Bprofile%7D/geojson/post)

Really easy to see all configuration options and directly see the result on a map and it’s raw response. Look for the parameter `attributes` and choose `avgspeed`.

---

<div class="post-metadata">

**Author:** ![nils](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nils/32/6_2.png) [@nils](https://ask.openrouteservice.org/u/nils)\
**Post date:** [March 20, 2019, 9:17am UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334/5 "2019-03-20T09:17:56Z")

</div>

Yeah, there’s multiple things wrong with your query:

1. No more GET requests, it’s all POST now, so your parameters go into the request body, not the query string (except for API key, which is still in the query string. Alternatively, use a request header `Authorization: <api_key>`)
2. `start`/`end` is not how you use ORS. The parameter is `coordinates` and takes a simple [[Lon, Lat]] list.

---

<div class="post-metadata">

**Author:** ![amandus](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/amandus/32/669_2.png) [@amandus](https://ask.openrouteservice.org/u/amandus)\
**Post date:** [March 21, 2019, 3:23pm UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334/6 "2019-03-21T15:23:10Z")

</div>

It is still possible to use GET with our V1 Api, also available in the playground if you switch `Api version` to V1:  
[https://api.openrouteservice.org/directions?api\_key=your-key&coordinates=start|end&profile=driving-car&attributes=avgspeed](https://api.openrouteservice.org/directions?api_key=your-key&coordinates=start%7Cend&profile=driving-car&attributes=avgspeed)

We **strongly recommend to use the V2** api as V1 is deprecated and will not be supported in the future (approximately 1 year).

---

<div class="post-metadata">

**Author:** ![richard.revesz](https://ask.openrouteservice.org/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@richard.revesz](https://ask.openrouteservice.org/u/richard.revesz)\
**Post date:** [April 2, 2019, 7:27am UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334/7 "2019-04-02T07:27:37Z")

</div>

Thank you.  
I am playing around with the API, and it seems like if “osmid” is required as extra info, it fails with api\_key error.  
Anything else seems to be working, only osmid is failing.  
What’s the matter with it?

(Both for [https://openrouteservice.org/dev/#/api-docs/v2/directions/{profile}/geojson/post](https://openrouteservice.org/dev/#/api-docs/v2/directions/%7Bprofile%7D/geojson/post) and [https://openrouteservice.org/dev/#/api-docs/v2/directions/{profile}/post](https://openrouteservice.org/dev/#/api-docs/v2/directions/%7Bprofile%7D/post))

---

<div class="post-metadata">

**Author:** ![richard.revesz](https://ask.openrouteservice.org/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@richard.revesz](https://ask.openrouteservice.org/u/richard.revesz)\
**Post date:** [April 2, 2019, 9:17am UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334/8 "2019-04-02T09:17:51Z")

</div>

Also, I am trying to implement it to Unity, and it seems I have a charset issue:

{“error”:{“message”:“Content type ‘application/x-www-form-urlencoded;charset=UTF-8’ not supported”},“info”:{“engine”:{“version”:“5.0”,“build\_date”:“2019-02-28T09:09:39Z”},“timestamp”:1554196364097}}  
UnityEngine.Debug:Log(Object)

So I have encoded the uri and the post data to ASCII and overwrote the header in the request, still it comes back with the same error

My code snippet (“request” = post data):

string notUTF8request = Encoding.ASCII.GetString(Encoding.UTF8.GetBytes(request), 0, request.Length);  
string notUTF8URI = Encoding.ASCII.GetString(Encoding.UTF8.GetBytes(URI), 0, URI.Length);

```
    UnityWebRequest www = UnityWebRequest.Post(notUTF8URI, notUTF8request);
    www.SetRequestHeader("Authorization", API_Key);
    www.SetRequestHeader("Charset", "ASCII");
    yield return www.SendWebRequest();

    Debug.Log(www.downloadHandler.text);

```

Any idea?

---

<div class="post-metadata">

**Author:** ![nils](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nils/32/6_2.png) [@nils](https://ask.openrouteservice.org/u/nils)\
**Post date:** [April 2, 2019, 9:39am UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334/9 "2019-04-02T09:39:21Z")

</div>

`content-type: application/json`

---

<div class="post-metadata">

**Author:** ![nils](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nils/32/6_2.png) [@nils](https://ask.openrouteservice.org/u/nils)\
**Post date:** [April 2, 2019, 9:45am UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334/10 "2019-04-02T09:45:41Z")

</div>

`osm_id` is not supported at this point, sorry.

---

<div class="post-metadata">

**Author:** ![richard.revesz](https://ask.openrouteservice.org/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@richard.revesz](https://ask.openrouteservice.org/u/richard.revesz)\
**Post date:** [April 2, 2019, 12:05pm UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334/11 "2019-04-02T12:05:40Z")

</div>

Ok, I got it working, thank you for helping me getting there!

For anyone else trying to use it from Unity:

Use WWW instead of UnityWebRequest.

UnityWebRequest Post only supports posting a string in UFT-8.  
I am not sure if the problem is the encoding or the fact that the posting seems to turn the string from this : “{ \ " coordinates \ " :…}” to this “{“coordinates”:…}” by the time it is getting sent, but as you have no option to control it by any ways or post raw data, you will get “JSONParseError: Unexpected character…”  
(I had to add spaces to show what I wrote, as this site also converted \ + " to " )  
(You could use Put instead of Post, but ORS does not support Put, so here it is not working).

You do not need UnityEngine.Networking, UnityEngine has WWW, for me it is working fine:

```
public string API_Key;
public string request;

public WWW Post(string request)
{
    Dictionary<string, string> postHeader = new Dictionary<string, string>();
    postHeader.Add("Content-Type", "application/json");
    postHeader.Add("Authorization", API_Key);
    byte[] requestData = Encoding.ASCII.GetBytes(request);
    WWW www= new WWW(URI, requestData, postHeader);
    StartCoroutine(WaitForRequest(www));
    return www;
}

IEnumerator WaitForRequest(WWW data)
{
    yield return data; // Wait until the download is done
    if (data.error != null)
    {
        Debug.Log("There was an error sending request: " + data.error);
    }
    else
    {
        Debug.Log("WWW Request: " + data.text);
    }
}
```

---

<div class="post-metadata">

**Author:** ![james](https://ask.openrouteservice.org/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@james](https://ask.openrouteservice.org/u/james)\
**Post date:** [May 30, 2019, 10:32am UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334/12 "2019-05-30T10:32:14Z")

</div>

It’s the max speed tag you want, if you want the speedlimits for each road.  
This would be super useful.  
[https://wiki.openstreetmap.org/wiki/Key:maxspeed](https://wiki.openstreetmap.org/wiki/Key:maxspeed)  
I notice mapquest provide this.  
I was hoping it might be possible to look this up programmatically but one would need the road id from OSM

---

<div class="post-metadata">

**Author:** ![jschnell](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/jschnell/32/971_2.png) [@jschnell](https://ask.openrouteservice.org/u/jschnell)\
**Post date:** [March 14, 2023, 9:49am UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334/13 "2023-03-14T09:49:04Z")

</div>

Split this topic on March 14, 2023, 9:49am UTC

A post was split to a new topic: [Average speed calculation for different periods of time](https://ask.openrouteservice.org/t/average-speed-calculation-for-different-periods-of-time/4652)

---

<div class="post-metadata">

**Author:** ![goncalo-oliveira](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/goncalo-oliveira/32/3336_2.png) [@goncalo-oliveira](https://ask.openrouteservice.org/u/goncalo-oliveira)\
**Post date:** [October 28, 2024, 4:29pm UTC](https://ask.openrouteservice.org/t/how-to-get-speed-limits-extra-information/334/14 "2024-10-28T16:29:50Z")

</div>

> It’s the max speed tag you want, if you want the speedlimits for each road.  
> This would be super useful.

Yeah, this was sort of what I was looking for. Any way to retrieve this information?
