Maps and location · from our own builds

Google Maps Directions API integration: route previews, live tracking and what each call costs

Integrating Google's Directions API in a delivery app takes a server-side proxy with a cache, a rule for when a drawn route is actually wrong, and a log line for every call that reaches Google. On Pakka the apps re-requested the route every ten seconds while the driver moved, about 151 billable calls on a 25-minute delivery, and we cut that to one per leg with a refetch only when the driver strays more than 150 m. A new project has to start on the Routes API instead, because Google stopped letting new Cloud projects enable the legacy Directions API in October 2026.

Updated 20 October 2026 · checked against our code and the vendors' documentation

Where have we built this?

  1. PakkaRoute preview, fare quote and live tracking in the customer and driver Android apps, all through the mobile backend's Directions proxy with a 10-minute Redis cache.
  2. PakkaBusiness-portal quotes priced on real road distance: one paid Directions call per lane, cached for 30 days, after a ×1.25 straight-line factor under-charged 72 of 90 measured Bengaluru routes.
  3. PakkaA coverage map for the operations console built on H3 hexagons at resolution 8, each counting the drivers within three rings, recomputed every 60 seconds with no call to Google.

What are the numbers and limits to know?

Directions API status
Legacy. As of October 2026 it can no longer be enabled for new Google Cloud projects; existing projects remain supported, and Google points new work to the Routes API.source, checked 20 October 2026
Directions (Legacy), Essentials
10,000 free billable events a month, then $5.00 per 1,000 in the 0–100,000 bandsource, checked 20 October 2026
Directions Advanced (Legacy), Pro
5,000 free a month, then $10.00 per 1,000. Applies to requests with traffic information, more than 10 waypoints, waypoint optimisation or location modifiers.source, checked 20 October 2026
Routes API: Compute Routes
Essentials: 10,000 free, then $5.00 per 1,000. Pro: 5,000 free, then $10.00 per 1,000.source, checked 20 October 2026
Places Autocomplete with a session token (Legacy)
Autocomplete in a session that ends in Place Details shows as $0; Place Details (Pro) has 5,000 free a month, then $17.00 per 1,000.source, checked 20 October 2026
Autocomplete without a session token
Each request is billed separately on Autocomplete – Per Request: 10,000 free, then $2.83 per 1,000.source, checked 20 October 2026
Map loads
Dynamic Maps: 10,000 free, then $7.00 per 1,000. The Maps SDK SKU is listed with unlimited free usage and no price.source, checked 20 October 2026
H3 cell at resolution 8
0.737 km² average area, 0.53 km average edgesource, checked 20 October 2026
Billable route calls on a simulated 25-minute Pakka delivery (apps)
About 151 before the fix, 1 after
Pakka's planning price per Directions call
₹0.43 ($0.005 at ₹85 to the dollar), marked in our notes to be checked against a real month of billing

How do you integrate Google Maps Directions API, step by step?

  1. 1

    Put every Google web-service call behind your backend

    Pakka's apps never call the Directions or Places web services themselves. The mobile backend does, so the server key stays on the server, every answer can be cached and every billable call can be counted. The phones hold only an app key restricted to each app's package name and signing SHA-1; the server key is restricted by IP address.

  2. 2

    Cache quotes, not movement

    The Directions cache keys on origin, destination and waypoints rounded to five decimal places and keeps each answer for 10 minutes, so the route preview, the fare quote and the driver's first route share one billed call. Reverse geocodes are kept for 7 days. Business-portal lanes are cached for 30 days: one paid call per lane, not per quote.

  3. 3

    Decide when a drawn route is actually wrong

    The apps fetch a route on a leg change (pickup to drop) or when nothing is drawn yet, and refetch only when the driver is more than 150 m from the line, measured to the nearest segment, at most once every 30 seconds. Movement alone never triggers a call from the apps. The rule is one pure function in a file that is byte-identical in the customer and driver apps.

  4. 4

    Count the ETA down on the phone

    Instead of asking Google again for a fresh ETA, each app derives the leg's average speed once from the distance and duration the route came back with, applies it to the distance left along the line, and trims the line to the road ahead.

  5. 5

    Move the driver's dot over your own socket

    The driver app sends its position after 20 m of movement, at most every 10 seconds, and the server relays it to the booking room over Socket.IO.

  6. 6

    Log every billable call with its price

    Each call the mobile backend's maps wrapper sends to Google writes a [maps-billable] log line with its approximate cost in paise. The wrapper warns once per boot when 25 Directions calls have run uncached because Redis is down, or 25 Places calls have arrived without a session token, the two silent multipliers we know about.

  7. 7

    Prove the call count with a test

    The test replays a 25-minute drive along a 5 km route, one position every 10 seconds, and asserts exactly one fetch. A negative control sends the driver off route and asserts that it refetches, so a fix that never fetches again cannot pass. Seven more cases pin the edges; all nine pass in both apps.

  8. 8

    Check unit prices against a real bill

    Our cost model uses public rates converted at ₹85 to the dollar. Before quoting a per-trip figure outside the team, pull one month from Cloud Billing by SKU and replace the assumed rows.

What went wrong, and how was it fixed?

A cache key that changed every metre

The server's Directions cache rounded coordinates to five decimal places, about 1.1 m. That is right for a quote, but during tracking the origin is a moving driver, so every request missed the cache and every one was billed. Redis was healthy the whole time, so the cache alarm stayed quiet.

Fix: The apps stopped asking for a route because the driver moved. Movement is handled on the phone, and the apps call Directions only on a leg change or a real deviation.

Comments that promised one fetch per leg

Both call sites said 'One fetch per leg' while the hook refetched every 10 seconds, about ₹2.58 a minute for each open map. The driver's trip screen stays open for the whole delivery, so a 30-minute trip made roughly 180 calls on that phone alone, and our per-trip cost report had priced live tracking at ₹0.00.

Fix: Fixed on 28 August 2026: the rule became a pure function with a call-count test over a simulated journey, and the cost report was corrected in place under a banner rather than rewritten.

Nearest vertex is not nearest road

Server polylines are sparse: on a straight road two vertices can be a kilometre apart. A driver halfway along is on the road but about 500 m from both ends, so a nearest-vertex check would call it a deviation and bring the cost straight back.

Fix: Measure to the nearest segment, clamped to its ends, with a local flat-earth projection cheap enough to run on every socket update.

Waypoints the client library encoded wrongly

@googlemaps/google-maps-services-js 3.4.2 with axios 1.20 sent waypoints as repeated query parameters instead of one pipe-joined value. Google read 'optimize:true' as an address, so every multi-stop quote since Bulk shipped on 15 September 2026 fell back to straight-line distance.

Fix: Found on 8 October 2026 by printing the request path: the request is now built with URLSearchParams, which Google accepts, and the distance sums every leg instead of the first.

Place Details that quietly returned only the pin

Passed as an array, the fields parameter made Google answer status OK with geometry only. formatted_address never came back, and the booking screen fell back to the autocomplete text for every address, which is why nobody noticed.

Fix: Pass fields as one comma-joined string. Checked against the live API, which then returned address components, formatted address, geometry, name and types.

An IP allowlist that missed IPv6

After a server move, address search answered 'No matches yet' while map tiles rendered fine. Tiles go from the phone under the app's SHA-1; search goes through the server key, and Google saw the server's IPv6 address, not the IPv4 one on the allowlist.

Fix: Allowlist both egress addresses on the server key, and re-check every Google surface after any move. The same cause had been fixed once before and was not carried across.

What should you check before going live?

  • Server key restricted to the server's IPv4 and IPv6 egress addresses
  • App keys restricted to package name and signing SHA-1
  • Every billable call writes a log line with its approximate price
  • A test asserts the number of route calls over a simulated trip
  • Failed route fetches back off, not only successful ones
  • Autocomplete sends a session token and ends the session with Place Details
  • Waypoint optimisation priced as Directions Advanced, not Directions
  • Unit prices checked against one month of Cloud Billing by SKU
  • New projects built on the Routes API, not the legacy Directions API

Questions about Google Maps Directions API

How many Directions calls should live tracking make per delivery?

In the apps, one per leg. Pakka's pickup and drop are two legs, and the apps refetch only if the driver is more than 150 m off the line, at most every 30 seconds; the moving dot itself comes over our own socket.

Why didn't a Redis cache stop the Directions bill?

Because the cache was keyed for quotes. A key rounded to about 1.1 m works when the same pickup and drop are asked twice, but during tracking the origin is a moving driver, so the key changes on every request. The fix was to stop requesting routes on movement, not to tune the cache.

Should a new app use the Directions API or the Routes API?

The Routes API. Google's Directions page says that as of October 2026 the legacy Directions API can no longer be enabled for new Cloud projects. Compute Routes Essentials is priced like legacy Directions, 10,000 free a month and then $5.00 per 1,000. Pakka still calls the legacy endpoint because its project predates the change.

Does a delivery app need Google to match drivers or show coverage?

No. Pakka finds nearby drivers with a MongoDB geospatial query and local distance maths, and its operations coverage map uses H3 hexagons computed on our own server every minute. Neither touches a billed Google API.

Is it worth paying for a real route on every business quote?

On Pakka it was. Straight-line distance times 1.25 under-charged 72 of 90 measured Bengaluru routes, with a mean error of −10%, while a 43-paise route call recovers ₹23–67 of fare. Business quotes now use real road distance, with one paid call per lane cached for 30 days.

What does Google bill when a user searches for an address?

With a session token, the autocomplete requests are free and the Place Details call that ends the session is billed. Without one, Google bills every keystroke request separately. Pakka logs and warns on tokenless calls and caps autocomplete at 30 requests per user per hour.

Need Google Maps Directions API in your app?

We have built it in production code, including the parts that went wrong. Tell us what your app needs and we'll say what it takes.

Ask about this integration