Avatar

How to pull road speed in .NET API

2

Hi,

I have report which shows the vehicle speed and the Road speed when an exception occurred for over speed.

How do i populate the road speed data? I see a method called "GetRoadMaxSpeeds()" but no idea how to use it!!

Any help will appreciated.

 

Thanks,

Akshay

 

 

akshay

Please sign in to leave a comment.

19 comments

Avatar

Hi Akshay,

The most efficient way to do this is to order all the speeding exceptions by device then date time. You can query GetRoadMaxSpeeds from the start of the first exception to the end date to the last exception for a device. This will return to you all the changes in posted road speed and the dates of these changes. It helps me to think of this data as a graph of all the speed changes over time. Using the results you can interpolate the posted road speed for all the exceptions for the device queried for at whichever time makes sense for your process (start of exception, max difference in speed, etc).

Hope that helps,

Steve

0
Comment actions Permalink
Steve Hansen 0 votes
Avatar

Hi Steve,

I understood your point. But I would like to know about the object definition for this "GetRoadMaxSpeeds" method. I am unable to implement this method in my .NET code.

 

--

Thanks,

Akshay

0
Comment actions Permalink
akshay 0 votes
Avatar

It is a Dictionary<DateTime, float> in .Net.

JSON representation is like: 

[{"k":"2014-03-16T04:58:58.063Z","v":50}]

Thanks,

Steve

0
Comment actions Permalink
Steve Hansen 0 votes
Avatar

Hi Steve,

a piece of sample code of implementation of this method will be appreciated.

 

--

Thanks,

Akshay

0
Comment actions Permalink
akshay 0 votes
Avatar

Hi,, Steve,

 

I would also like to see an example of C# code for this method.

 

0
Comment actions Permalink
Faron Hancox 0 votes
Avatar

Hey Guys,

There is a snippet that illustrates how to "Get Device Speeds and Road Speeds for a Day" in the snippets section of the SDK. The snippets are in JavaScript but it should be simple to convert to C#.

Thanks,

Steve

0
Comment actions Permalink
Steve Hansen 0 votes
Avatar

Steve,

It works in JavaScript fine.  But .NET throws an error internally from Geotab.  See pictures. 

private Dictionary<DateTime, float> GetRoadMaxSpeeds(Id deviceID, DateTime fromDate, DateTime toDate)

{            

try           

{                

Dictionary<DateTime, float> roadMaxSpeedDict = _api.Call<Dictionary<DateTime, float>>("GetRoadMaxSpeeds", new                 {                                       

DeviceSearch = new DeviceSearch { Id = deviceID },                    

FromDate = fromDate,                    

ToDate = toDate                

});                                               

return roadMaxSpeedDict;           

}            

catch            

{                

throw;            

}        

}

 

 

Michael




GetRoadMaxSpeedsError.PNG
GetRoadMaxSpeeds_Error2.png
0
Comment actions Permalink
Michael Head 0 votes
Avatar

Hey Mike,

Try with lowercase property names from dot net when using anonymous object:

Dictionary<DateTime, float> roadMaxSpeedDict = _api.Call<Dictionary<DateTime, float>>("GetRoadMaxSpeeds", new                 {                                       

    deviceSearch = new DeviceSearch { Id = deviceID },
    fromDate = fromDate,
    toDate = toDate             

});    

Thanks,

Steve         

0
Comment actions Permalink
Steve Hansen 0 votes
Avatar

Your the man.  It works with lowercase property names.  Thanks for the heads up.

0
Comment actions Permalink
Michael Head 0 votes
Avatar

Hi Steve,

I also need to use this method on our 5.6 servers however I keep receving an error message:

Unable to cast object of type 'System.Double' to type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]'.

The code I am using is shown below:

  

sc = new SimpleCoordinate();

//longitude and latitude are valid values extracted from a logRecord

sc.X = longitude;

sc.Y = latitude;

List<SimpleCoordinate> scList = new List<SimpleCoordinate>();

                    scList.Add(sc);

Dictionary<DateTime, float> roadMaxSpeedDict = api.Call<Dictionary<DateTime, float>>("GetRoadMaxSpeeds", new

                        {

                            simplePoints = scList

                        });

0
Comment actions Permalink
Faron Hancox 0 votes
Avatar

I don't have access to a 5.6 database but the 5.6 version of "GetRoadMaxSpeeds" returns "An array of the metric posted road speeds."

 

0
Comment actions Permalink
Michael Head 0 votes
Avatar

Hi

I want to get posted road speed for a particular latitude and longitude how will i get it?

at present i am using the below code but it returns a set of data irrespective of the date time passed

Dictionary<DateTime, float> roadMaxSpeedDict = api.Call<Dictionary<DateTime, float>>("GetRoadMaxSpeeds", new
{

fromDate = exception.ActiveFrom,
toDate = exception.ActiveTo,
deviceSearch = new DeviceSearch { Id = devices[0].Id }

});

 

please suggest

 

0
Comment actions Permalink
akshay 0 votes
Avatar

Hi

Can you please help me on above problem as soon as possible as i am stuck in my application and I need this information to move forward .

Thanks

Akshay

0
Comment actions Permalink
akshay 0 votes
Avatar

You will want to use the GetMaxRoadSpeeds method.

I have found that the most efficient way to get posted road speed for speeding exceptions in the context of a report is to aggregate the exceptions by device. Then find the earliest start data and latest end date. Then, make the request to GetMaxRoadSpeeds  using those dates and the device ID. Rinse and repeat for each device. This will return a list of all the speed limit changes in that time. - It helps me to think of this like the speed graph in MyGeotab that shows posted road speed. Then iterate through the list of exceptions and the speed limit changes to see what the speed limit was at the time of the exception. Keep in mind that the speeding event may have taken place though one or many different speed zones. You may want to introduce logic here for which one has the most meaning to your report. For example: the largest difference between vehicle speed and speed limit or the speed limit at the start of the exception, etc.

That should give you enough information to get started.

Thanks,

Steve

0
Comment actions Permalink
Steve Hansen 0 votes
Avatar

Hi Steve

As you said i Have passed the exception start Date Time and End Date Time and the  device ID but this returns a  list of all the speed limit changes in that Date and not based on time .

I want the posted road speed during the exception occurred .

I am attaching the snap shot of the scenario

Thanks,

akshay   




Max Road Spped.png
MaxRoadSpeed2.png
0
Comment actions Permalink
akshay 0 votes
Avatar

There could be many posted speed changes during the time of an exception. This is where you may want to introduce logic for which posted speed has the most meaning to your report. For example: the largest difference between vehicle speed and speed limit or the speed limit at the start of the exception, etc.

0
Comment actions Permalink
Steve Hansen 0 votes
Avatar

Hi Steve

As shown in the example the exception started at 10.43.54 AM to 10.44.40 AM but the GetRoadMax returns a list of speed for the whole day and not for the particular date time which are my search parameters .

Also to apply logic and to get the posted road speed at the time of exception is bit tricky as the list shows that at 10.41.50 AM the Speed was 72 and at 10.45.10 Am the speed was 82 and the exception occurred between this time. so what is the actual posted road speed at the time of exception ?

Please suggest.

Thanks,

Rasik

 

 

0
Comment actions Permalink
akshay 0 votes
Avatar

Unfortunately, in your example only showed the start time of the exception, not the end. Thanks for making that more clear.

The speed limits returned are the speed changes. The speed limit is constant until the next value - think of it like from one speed limit sign to the next. You should not expect to get back the speed limit for the exact time of the exception event start. Consider the image below (apologies for my crude drawing). Given the changes in posted road speed you know what the speed limit was at a given time.

speedgraph.png

0
Comment actions Permalink
Steve Hansen 0 votes
Avatar

Hi Steve

Thanks for the example your image cleared all my doubts.

Thanks

Akshy

0
Comment actions Permalink
akshay 0 votes