How to Route Around a Road Closure or Location
- API or service
- Routing API
- Task
- Waypoints and blocked location → detour
- Examples
- Difficulty
- Intermediate
- Time
- 7 min
Route around a road closure or location
Your application knows that a road location is closed, blocked, or unsuitable and needs a route that detours around it. Add the location to the Routing API avoid parameter while keeping the origin, destination, and travel mode unchanged.
The Routing API does not discover live closures from this parameter. Your application supplies the blocked location from an operational feed, administrator input, or other trusted source.
Task flow: origin, destination, and blocked location → Routing API → alternative route around that location when possible.
Avoid a route location
First calculate the normal route between Brandenburg Gate and Museum Island in Berlin:
https://api.geoapify.com/v1/routing?waypoints=52.5163,13.3777|52.5169,13.4010&mode=drive&format=geojson&apiKey=YOUR_API_KEY
Then identify a point on the unavailable road and add it as an avoid rule. The location_lonlat form uses longitude,latitude order:
https://api.geoapify.com/v1/routing?waypoints=52.5163,13.3777|52.5169,13.4010&mode=drive&avoid=location_lonlat:13.393068,52.517153&format=geojson&apiKey=YOUR_API_KEY
Reduced response comparison:
{
"normal_route": {
"distance": 1758,
"time": 178.929
},
"route_avoiding_location": {
"distance": 1793,
"time": 200.742
}
}
The avoid rule changes both the geometry and the estimate: the detour is 35 meters longer and about 21.8 seconds slower for this example.
Model closures safely
An avoided location is a routing preference, not a road-closure management system or an absolute exclusion. For production use:
- obtain closure coordinates from a maintained source and remove rules when a closure expires;
- use
location_lonlat:<longitude>,<latitude>orlocation:<latitude>,<longitude>consistently; - add multiple location rules when a closure affects a longer corridor rather than one point;
- confirm that the returned geometry does not traverse the operationally blocked segment;
- handle the case where no suitable alternative is available;
- recalculate cached routes when closure information changes.
Do not infer a closure from traffic=approximated. The traffic model changes expected speeds on roads likely to be congested; it does not represent a live closure feed.