Skip to main content

REST APIs

Overview

Forcodes REST API provides endpoints for encoding and decoding geographic coordinates using the Forcodes geocoding system. Forcodes generates compact, human-friendly strings that embed Vietnamese administrative codes and hexagonal spatial indexing.

Base URL

The base URL for all API requests is:

https://mapapis.openmap.vn/v1

Authentication

All API requests must include an API key.

To use the API Key, you need to include apikey parameter in the query of your API requests. This allows the server to identify and authenticate the user or application making the request.

info

To get an API Key, you need to sign up for an account on the Openmap.vn platform here, or reach us at [email protected].

Endpoints

1. Encode Coordinates to Forcode

Convert latitude/longitude coordinates to a Forcode string.

Endpoint: POST /forcodes/encode?lat={lat}&lng={lng}&resolution={resolution}

Parameters:

  • lat (required): Latitude in decimal degrees
  • lng (required): Longitude in decimal degrees
  • resolution (optional): Hexagon resolution level (0-15). Default: 13

Response:

{
"forcodes": "HN4TZUZBPKRN0F",
"lat": 20.990396,
"lng": 105.868825,
"resolution": 13,
"admin_code": "HN",
"status": "OK"
}

Response Fields:

  • forcodes: Generated Forcode string
  • lat: Input latitude
  • lng: Input longitude
  • resolution: Hexagon resolution used
  • admin_code: Vietnamese province/city code
  • status: Operation status

2. Decode Forcode to Coordinates

Convert a Forcode string back to latitude/longitude coordinates.

Endpoint: POST /forcodes/decode

Parameters:

  • forcodes (required): Forcode string to decode

Response:

{
"lat": 20.99029428701167,
"lng": 105.86868969733383,
"resolution": 11,
"forcodes": "HNO4DT45BQNZ",
"status": "OK"
}

Response Fields:

  • lat: Decoded latitude
  • lng: Decoded longitude
  • resolution: Hexagon resolution level
  • forcodes: Input Forcode string
  • status: Operation status

Error Response:

{
"lat": null,
"lng": null,
"resolution": null,
"forcodes": "INVALID",
"status": "INVALID_FORCODES"
}

HTTP Status Codes

  • 200 OK: Request successful
  • 400 Bad Request: Invalid input parameters
  • 404 Not Found: Resource not found

Hexagon Resolution Levels

Forcodes uses hexagonal spatial indexing with different resolution levels:

ResolutionHexagon Edge LengthTypical Use Case
0~1,107 kmContinental areas
1~418 kmLarge regions
2~158 kmMedium regions
3~59 kmSmall regions
4~22 kmLarge cities
5~8.5 kmCity districts
6~3.2 kmNeighborhoods
7~1.2 kmLarge buildings
8~461 mCity blocks
9~174 mLarge buildings
10~66 mBuilding groups
11~25 mIndividual buildings
12~9.4 mLarge rooms
13~3.5 mSmall rooms
14~1.3 mPrecise locations
15~0.5 mVery precise locations

Administrative Codes

Forcodes embed Vietnamese province/city codes based on the 2025 administrative structure:

CodeNew Province/City NameMerged Provinces/Cities
TQTuyên QuangHà Giang, Tuyên Quang
CBCao BằngCao Bằng
LCULai ChâuLai Châu
LCILào CaiLào Cai, Yên Bái
TNThái NguyênBắc Kạn, Thái Nguyên
DBĐiện BiênĐiện Biên
LSLạng SơnLạng Sơn
SLSơn LaSơn La
PTPhú ThọHòa Bình, Vĩnh Phúc, Phú Thọ
BNBắc NinhBắc Giang, Bắc Ninh
QNHQuảng NinhQuảng Ninh
HNHà NộiHà Nội
HPHải PhòngHải Dương, Hải Phòng
HYHưng YênThái Bình, Hưng Yên
NBNinh BìnhHà Nam, Ninh Bình, Nam Định
THThanh HóaThanh Hóa
NANghệ AnNghệ An
HTHà TĩnhHà Tĩnh
QTQuảng TrịQuảng Bình, Quảng Trị
HUEHuếHuế
DNGĐà NẵngQuảng Nam, Đà Nẵng
QNGQuảng NgãiQuảng Ngãi, Kon Tum
GLGia LaiGia Lai, Bình Định
DLKĐắk LắkPhú Yên, Đắk Lắk
KHKhánh HòaKhánh Hòa, Ninh Thuận
LDLâm ĐồngĐắk Nông, Lâm Đồng, Bình Thuận
DNĐồng NaiBình Phước, Đồng Nai
TNHTây NinhLong An, Tây Ninh
HCMTP. Hồ Chí MinhBình Dương, TP.HCM, Bà Rịa - Vũng Tàu
DTĐồng ThápTiền Giang, Đồng Tháp
AGAn GiangKiên Giang, An Giang
VLVĩnh LongBến Tre, Vĩnh Long, Trà Vinh
CTCần ThơSóc Trăng, Hậu Giang, Cần Thơ
CMCà MauBạc Liêu, Cà Mau