Snap to Road
Snap GPS coordinates to the nearest road
POST
/routing/snapSnap GPS coordinates to the nearest road segment. Corrects GPS drift and ensures coordinates align with the road network.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
coordinates | Coordinates[] | Yes | Array of GPS coordinates to snap |
radius | number | No | Maximum snap distance in meters (default: 50) |
Coordinates
| Field | Type | Required | Description |
|---|---|---|---|
lat | number | Yes | Latitude |
lng | number | Yes | Longitude |
Example Response
Response Fields
| Field | Type | Description |
|---|---|---|
snapped | SnappedPoint[] | Successfully snapped coordinates |
unsnapped | number[] | Indices of points that couldn't be snapped within radius |
SnappedPoint
| Field | Type | Description |
|---|---|---|
location | Coordinates | Snapped position on road |
originalIndex | number | Index in the original input array |
distance | number | Distance from original point in meters |
name | string | Road name (if available) |
Use Cases
- GPS Correction: Fix inaccurate GPS readings from mobile devices
- Route Reconstruction: Convert raw GPS traces to road-following paths
- Address Validation: Ensure pickup/dropoff coordinates are on valid roads
- Map Matching: Align vehicle positions to the road network for tracking
Handling Unsnapped Points
Points that cannot be snapped within the specified radius are returned in the unsnapped array. This can happen when:
- The point is too far from any road
- The point is in an area without road coverage
- The radius is set too small
In this example, points at indices 1 and 2 could not be snapped.
Best Practices
- Use a radius of 50-100m for typical GPS accuracy
- For high-accuracy GPS (RTK/DGPS), use a smaller radius (10-20m)
- Process coordinates in batches for efficiency
- Handle
unsnappedpoints gracefully in your application