How to Build Delivery Zones in Vietnam using Map APIs
A step-by-step developer tutorial on how to implement location-based service boundaries, calculate shipping fees, and filter regions in Vietnam.
If you are building an e-commerce store, a food-delivery app, or a shipping platform in Vietnam, one of the first problems you need to solve is: How do we outline our service coverage area and calculate shipping fees automatically?
Many teams start by calculating costs based on a simple straight-line radius (e.g. 2km, 5km). However, this method is highly inaccurate in Vietnamese urban centers due to rivers, bridges, one-way roads, and gridlocked traffic.
The industry standard, used by major platforms like Grab, Shopee, and Giaohangtietkiem, is segmenting delivery zones based on administrative boundaries (District and Ward boundaries).
This article provides a step-by-step guide to building a delivery zone system in code, using boundary datasets from GoGoDuk Map API and the Turf.js helper library.
The Delivery Zone System Architecture
A robust delivery zoning flow works in 4 steps:
- Define Service Zones: Retrieve the geographic boundary polygons for the districts or wards you intend to service.
- Normalize Customer Input: When a customer types their address at checkout, use autocomplete to suggest matching places and resolve the selection into a GPS coordinate (latitude/longitude).
- Point-in-Polygon Check: Run a geometric check to see which district boundary polygon contains the customer's coordinate.
- Calculate Pricing: Apply the pre-configured delivery fee associated with that matched boundary zone.
Step 1: Retrieve Vietnam Administrative Boundaries
Instead of licensing expensive boundary datasets, you can query GoGoDuk's /v1/admin-boundaries endpoint to fetch GeoJSON polygons for Vietnam's 63 provinces and 700+ districts for free.
For example, to fetch the boundaries of District 1, Ho Chi Minh City:
The response contains the geometry coordinates of the boundary:
Step 2: Autocomplete and Resolve Address to Coordinates
To avoid typos and address errors during checkout, use the autocomplete suggest endpoint to help users pick a valid Vietnamese address.
Once the user selects a place (exposing a placeId like gdk_place_12345), resolve it to get GPS coordinates:
Step 3: Run Point-in-Polygon Check
At this stage, you have the customer's location as a GPS coordinate Point = [lon, lat], and the district boundary as a Polygon. You need to evaluate whether the point lies inside the polygon.
You can perform this containment check at the database level (using PostgreSQL PostGIS ST_Contains) or inside your Node.js or browser application using the open-source Turf.js library.
Install Turf.js utilities:
Evaluate containment in JavaScript:
Step 4: Automate Shipping Fee Calculations at Checkout
To compute shipping costs dynamically, store shipping rates mapped to administrative zones in your database:
| Service Area (District ID) | Delivery Fee | Expected Delivery Time |
|---|---|---|
| District 1 | 15,000 VND | 15-30 mins |
| Binh Thanh District | 20,000 VND | 30-45 mins |
| District 7 | 30,000 VND | 45-60 mins |
Here is a full checkout route implementation in Node.js:
Conclusion
Calculating shipping fees using real administrative boundary polygons instead of geometric distance circles eliminates disputes with delivery drivers, lowers checkout friction, and allows precise dispatch forecasting.
With GoGoDuk's regularly updated boundary dataset and Vietnamese-optimized autocomplete APIs, you can build a production-ready delivery dispatch system in a few hours.
Start building today for free by visiting the GoGoDuk API Documentation.
Want to use GoGoDuk?
Free forever — 100 requests/day per account, no credit card. Higher limits on request.
Sign up →