Route Instructions via WS
Table of contents
How to get Route Instructions
If you use getFull of the Route Web service 2.0, you get also an array back with Route Instructions.
You can also can get the instructions via getInstructions of the Route Web service 2.0
Structure of Route Instructions
Example
array (
0 =>
array (
'atGeometry' => 'POINT(3.336239 50.985226)',
'distance' => 0,
'using' => 'Seyntexlaan',
'toBearing' => 91,
'at' => NULL,
'to' => NULL,
'angle' => NULL,
'fromBearing' => NULL,
),
1 =>
array (
'atGeometry' => 'POINT(3.337471 50.985227)',
'distance' => 86.299999999999997,
'fromBearing' => 90,
'toBearing' => 154,
'at' => NULL,
'to' => NULL,
'using' => '',
'angle' => 64,
),
2 =>
array (
'atGeometry' => 'POINT(3.338891 50.982745)',
'distance' => 381,
'using' => 'Bosakkerstraat',
'fromBearing' => 163,
'toBearing' => 135,
'at' => NULL,
'to' => NULL,
'angle' => -28,
),
3 =>
array (
'atGeometry' => 'POINT(3.338637 50.973727)',
'distance' => 1429.7,
'using' => 'Sint-Pieterstraat',
'fromBearing' => -152,
'toBearing' => 127,
'at' => NULL,
'to' => NULL,
'angle' => -81,
),
4 =>
array (
'atGeometry' => 'POINT(3.350291 50.970617)',
'distance' => 2333.5,
'using' => 'Sint-Martensstraat',
'fromBearing' => 54,
'toBearing' => 28,
'at' => NULL,
'to' => NULL,
'angle' => -26,
),
5 =>
array (
'atGeometry' => 'POINT(3.354968 50.973111)',
'distance' => 2795.9000000000001,
'using' => 'Putterijstraat',
'fromBearing' => 55,
'toBearing' => 54,
'at' => NULL,
'to' => NULL,
'angle' => -1,
),
6 =>
array (
'atGeometry' => 'POINT(3.367613 50.978386)',
'distance' => 3877.5999999999999,
'using' => 'Tieltseweg',
'fromBearing' => 50,
'toBearing' => 155,
'at' => NULL,
'to' => NULL,
'angle' => 105,
),
7 =>
array (
'atGeometry' => 'POINT(3.38004 50.9702)',
'distance' => 5184.3000000000002,
'using' => 'Tieltseweg',
'fromBearing' => 148,
'at' => NULL,
'to' => NULL,
'angle' => NULL,
'toBearing' => NULL,
),
)
Meaning of the variables
atGeometry
Example: 'atGeometry' => 'POINT(3.338637 50.973727)'
This indicated the exact point in WGS84 coordinates (Longtiude or X, Latitude or Y) where the instruction refers to.
Example, turning right from Street A into Street B, the POINT will indicate the position of the intersection of Street A with Street B.
Remark: This is not the same as the place where you should give the instruction (that depends how fast you drive/walk)
distance
Example:'distance' => 5184.3000000000002,
This indicated the exact point in meters from the start of the route (NOT from the PREVIOUS instruction).
using
Example: 'using' => 'Tieltseweg'
This means the street you go to AFTER the manoeuvre/instruction you made. To know the street you come from you have to take the previous instruction.
Remark: This variable can be omitted in case there is no streetname known.
fromBearing & toBearing
Example: 'fromBearing' => 179,
'toBearing' => 44,
Descr: The fromBearing
means that BEFORE the instruction (atGeometry), you are following direction 179° from north (this is the bearing, so you are going south), and the toBearing
means that you will follow the direction 44° from north, AFTER the instruction (atGeometry) (so you are going east).
This is also the way to know what kind of icon or 'instruction name' you should use to indicate the instructions. To get the angle Subtract the 'fromBearing' with the
'toBearing'
: go straight
: bear left
: bear right
: turn left
: turn right
: sharp right
: sharp left
: U-turn
The following code can be used to translate the angle and the direction to the instruction:
angleToInstructionCode($angle)
{
$direction = ($angle > 0) ? 'right' : 'left';
$angle = abs($angle);
if ($angle <= 15)
$instruction = 'straight';
else if ($angle > 15 && $angle <= 75)
$instruction = 'bear_' . $direction;
else if ($angle > 75 && $angle <= 105)
$instruction = $direction;
else if ($angle > 105 && $angle <= 175)
$instruction = 'sharp_' . $direction;
else
$instruction = 'uturn';
return $instruction;
}
at & to
example: 'at' => NULL, 'to' => NULL,
or
example: 'at' => 16, 'to' => 22,
In general the at & to will be NULL, except in the case of instructions linked to a node network. Read here more about the concept of the node network
angle
Example: 'angle' => -26,
The angle is the 'toBearing'
- 'fromBearing'. So in this case
'fromBearing' => 54, 'toBearing' => 28
importance (planned, not active yet!)
Check here for more information and the meaning of the importance