moovexDocs

Snap to Road

Snap GPS coordinates to the nearest road

POST/routing/snap

Snap GPS coordinates to the nearest road segment. Corrects GPS drift and ensures coordinates align with the road network.

Request Body

FieldTypeRequiredDescription
coordinatesCoordinates[]YesArray of GPS coordinates to snap
radiusnumberNoMaximum snap distance in meters (default: 50)

Coordinates

FieldTypeRequiredDescription
latnumberYesLatitude
lngnumberYesLongitude
{ "lat": 40.7128, "lng": -74.0060 }

Example Response

{
  "snapped": [
    {
      "location": { "lat": 40.712801, "lng": -74.005982 },
      "originalIndex": 0,
      "distance": 2.3,
      "name": "Broadway"
    },
    {
      "location": { "lat": 40.713512, "lng": -74.005791 },
      "originalIndex": 1,
      "distance": 1.8,
      "name": "Broadway"
    },
    {
      "location": { "lat": 40.714198, "lng": -74.005489 },
      "originalIndex": 2,
      "distance": 2.1,
      "name": "Broadway"
    }
  ],
  "unsnapped": []
}

Response Fields

FieldTypeDescription
snappedSnappedPoint[]Successfully snapped coordinates
unsnappednumber[]Indices of points that couldn't be snapped within radius

SnappedPoint

FieldTypeDescription
locationCoordinatesSnapped position on road
originalIndexnumberIndex in the original input array
distancenumberDistance from original point in meters
namestringRoad 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
{
  "snapped": [
    {
      "location": { "lat": 40.712801, "lng": -74.005982 },
      "originalIndex": 0,
      "distance": 2.3
    }
  ],
  "unsnapped": [1, 2]
}

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 unsnapped points gracefully in your application

On this page