Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using google maps API to find average speed at a location

Tags:

google-maps

I am trying to get the current traffic conditions at a particular location. The GTrafficOverlay object mentioned here only provides an overlay on an existing map.

Does anyone know how I can get this data from Google using their API?

like image 386
Animesh Avatar asked Jan 28 '26 14:01

Animesh


1 Answers

It is only theorical, but there is perhaps a way to extract those data using the distancematrix api.

Method

1)

Make a topological road network, with node and edge, something like this:

enter image description here

Each edge will have four attributes: [EDGE_NUMBER;EDGE_SPEED;EDGE_TIME,EDGE_LENGTH] You can use the openstreetmap data to create this network. At the begining each edge will have the same road speed, for example 50km/h. You need to use only the drivelink and delete the other edges. Take also into account that some roads are oneway.

2)

Randomly chose two nodes that are not closer than 5 or 10km

  • Use the dijsktra shortest path algorithm to calculate the shortest path between this two nodes (the cost = EDGE_TIME). Use your topological network to do that. The output will look like:

    NODE = [NODE_23,NODE_44] PATH = [EDGE_3,EDGE_130,EDGE_49,EDGE_39]

  • Calculate the time needed to drive between the two nodes with the distance matrix api.

Preallocate a matrix A of size N X number_of_edge filled with zero value Preallocate a matrix B of size 1 X number_of_edge filled with zero value

In the first row of matrix A fill each column (corresponding to each edge) with the length of the edge if the corresponding edge is in the path.

[col_1,col_2,col_3,...,col_39,...,col_49,...,col_130]
[0,    0,    len_3,...,len_39,...,len_49,...,len_130] %row 1

In the first row of matrix B put the time calculated with the distance matrix api.

Then select two news node that were not used in the first path and repeat the operation until that there is no node left. (so you will fill the row 2, the row 3...)

Now you can solve the linear equation system: Ax = B where speed = 1/x

Assign the new calculated speed to each edge.

3)

Iterate the point 2) until your calculated speed start to converge.

Comment

I'm not sure that the calculated speed will converge, it will be interesting to test the method.I will try to do that if I got some time. The distance matrix api don't provide a traveling time more precise than 1 minute, that's why the distance between the pair of node need to be at least 5 or 10 or more km. Also this method fails to respect the Google's terms of service.

like image 164
obchardon Avatar answered Jan 31 '26 19:01

obchardon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!