# getClosestStraightRoad (Shared)

> Finds the stretch of road closest to a point: two linked car nodes and the heading between them. Switched-off nodes are left out.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Roads and paths
- **URL**: https://wiki.mymp.gg/en/getClosestStraightRoad

## Syntax

```lua
vec3, vec3, float|false getClosestStraightRoad(float x, y, z [, float minLength = 0, float maxDistance = 999999.875])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `x, y, z` | `float` | The point to search from. |
| `minLength` | `float` | The least distance in metres between the two nodes. *(default: `0`)* |
| `maxDistance` | `float` | How far from the point the stretch may be. *(default: `999999.875`)* |

## Returns

The two nodes' positions, beside the median as `getPathNodePosition` with `lane` gives them, and the heading from the second to the first in degrees. `false` if no stretch was found.

## Example

```lua
local vehicle = getPedOccupiedVehicle(localPlayer)
if vehicle then
    local position = getElementPosition(vehicle)
    local first, second, heading = getClosestStraightRoad(position.x, position.y, position.z, 10, 200)
    if first then
        setElementPosition(vehicle, first.x, first.y, first.z + 1)
        setElementRotation(vehicle, 0, 0, heading)
    end
end
```

### Note

Only nodes in loaded path areas count: those near the player, or requested with `requestPathNodesInArea`.

## See also

- [getClosestPathNode (Shared)](https://wiki.mymp.gg/en/getClosestPathNode.md): Finds the road or footpath node closest to a point.
- [getPathNodePosition (Shared)](https://wiki.mymp.gg/en/getPathNodePosition.md): Returns a path node's position.
