Setting Up a Local Routing Stack

Most people throw money at commercial APIs without realizing they can run decent routing locally. I set up a local OSRM instance on a spare VPS and cut my monthly routing costs from about $85 to zero, though it cost me roughly 45 minutes of dev time to get it right. Here's how I actually did it. The basic flow is: geocode your current location to coordinates, geocode your destination, call a router, then parse the resulting geometry into human-readable steps. The geocoding step trips people up more than anything else because phone GPS drifts. A single "current location" read from a phone might land you 20 meters into the next intersection overpass, which turns a straightforward right turn into "turn around." I started grabbing three readings, taking a simple average, and using that as the official start point instead of trusting one GPS lock. Saved me from generating directions that pointed people at highway medians for months.

Turn By Turn How To Generate Step By Step Driving Directions From My Location

Here's the direct path. You'll need a router, a geocoder, and a little bit of code connecting them. Option A: OpenStreetMap-based local setup (free) Download OSRM from GitHub. Run the preprocessing tool on the OSM extract for your country or region, then spin up the server with docker run -p 5000:5000 osrm/osrm-backend pointing at your processed .osrm files. Geocode using Nominatim, also open source, or just use PostGIS against the OSM planet dump if you want speed. Call /route/v1/driving/LON1,LAT1;LON2,LAT2?steps=true&geometries=geojson and parse the response. The steps array contains everything you need: maneuver type, road name, distance, duration, and the geometry line for the segment.

Option B: Commercial APIs (fastest to deploy) Mapbox Directions API and Google Routes API both return turn-by-turn instructions out of the box. With Mapbox you set steps=true in the request and get back an array where each element has a mode, maneuver, name, distance, and duration. Cost is roughly $0.50 per 1,000 requests at the standard tier. For a small app this is usually fine. For anything above a few hundred thousand requests per month it gets expensive fast. Google's newer Routes API gives you step objects inside each routeLeg that include instruction text, distanceMeters, and durationSeconds. The free tier gives you $200 in credits monthly, which handles about 100,000 route requests. After that it's $0.50 per 1,000 for the basic route response.

Get the Full Details

How to Get Turn by Turn Directions on Google Maps
How to Get Turn by Turn Directions on Google Maps

The Edge Case Nobody Warns You About

Last year I was building directions for a delivery app in a suburban area with a lot of divided roads. OSRM's default profile was classifying a simple lane merge as a separate maneuver, so the generated directions told the driver to "merge right," then immediately "merge left" because the road widened and then narrowed again. Two steps that should have been one. The workaround was setting avoid_features=["ferries","motorways"] wasn't the issue here, it was enabling the suppress_maneuvers=false flag and then post-processing the step list. I wrote a small dedup pass that merged consecutive same-direction maneuvers on the same road name into a single instruction. That cut the step count by about 30% in practice and made the directions actually usable. This kind of thing doesn't show up in the documentation. You only find it when your users start complaining that the app told them to make a U-turn at a gas station.

Practical Implementation Details

If you're coding this yourself, here's what the actual request looks like with Mapbox, which is the cleaner of the two APIs: GET https://api.mapbox.com/directions/v5/mapbox/driving/-73.9857,40.7484;-74.0060,40.7128?steps=true&geometries=geojson&access_token=YOUR_TOKEN The first coordinate pair is your current location, the second is your destination. You must reverse the order to LON,LAT format. That trips up more people than any other single mistake. The response has a routes array, each route has legs, each leg has steps. Each step has a maneuver object with a type field that tells you if it's a depart, turn, merge, fork, destination, or arrive.

For geocoding your current position from a street address instead of raw coordinates, use Mapbox Geocoding API or Nominatim. Nominatim is free but rate-limited to one request per second unless you register. I registered mine and got 50 requests per second, which is plenty for most use cases.

How to Get Turn by Turn Directions on Google Maps
How to Get Turn by Turn Directions on Google Maps

When This Approach Falls Apart

Local routing with open data struggles in rural areas where road data is outdated. OSM coverage in parts of the American Midwest and rural Australia can be months behind reality after construction. If you're generating directions for a fleet that operates in those areas, you'll miss new subdivisions and closed roads until the next community edit cycle. Commercial providers update their maps continuously and generally catch these changes within days. Another failure mode: toll roads. OSRM's default driving profile doesn't account for tolls. If your users care about avoiding tolls or minimizing toll cost, you need either a custom profile with toll data layered in, or you switch to a paid API that has that metadata. Google Maps has a avoidTolls parameter built in. Mapbox has a similar option but it requires the Premium plan. If you need turn-by-turn directions that work reliably in a production app and you don't want to maintain your own infrastructure, I'd just use Mapbox. The setup takes about 20 minutes from zero to working code. If you're processing fewer than 10,000 routes per month and the directions just need to be roughly correct, OSRM on a local server is fine and free. Beyond that, the maintenance overhead of keeping your OSM extracts fresh starts eating into your time faster than the API costs would.